使用pywinauto如何 获取systreeview32内的item(python语言)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用pywinauto如何 获取systreeview32内的item(python语言)相关的知识,希望对你有一定的参考价值。
要获取这个对话框中的买入子菜单
①SysListView32#define TEXTSIZE 256
void Func()
HWND hYF; //SysListView32的父窗口句柄
HWND hLV = FindWindowEx(hYF, NULL, _T("SysListView32"), _T(""));
DWORD PID;
HWND hWnd; //hWnd 应用程序的句柄
GetWindowThreadProcessId(hWnd, &PID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
TCHAR buf[TEXTSIZE];
TCHAR lpClassName[TEXTSIZE];
while(1 && (NULL != hLV))
GetClassName(hLV, (LPWSTR)lpClassName, TEXTSIZE-1); //获得窗口类名
CString className(lpClassName);
if (className != _T("SysListView32"))
continue;
CListView* pListView = (CListView*)CWnd::FromHandle(hLV);
CListCtrl& listCtrl = pListView->GetListCtrl();
LVCOLUMN* plvcolumn =(LVCOLUMN*)VirtualAllocEx(hProcess, NULL, sizeof(LVCOLUMN), MEM_COMMIT, PAGE_READWRITE);
TCHAR* pColumnTitle = (TCHAR*)VirtualAllocEx(hProcess, NULL, TEXTSIZE, MEM_COMMIT, PAGE_READWRITE);
LVCOLUMN lvcol;
lvcol.pszText = pColumnTitle;
lvcol.cchTextMax = TEXTSIZE;
lvcol.mask = LVCF_TEXT;
WriteProcessMemory(hProcess, plvcolumn, &lvcol, sizeof(LVCOLUMN), NULL);
listCtrl.GetColumn(0, plvcolumn);
ReadProcessMemory(hProcess, pColumnTitle, buf, TEXTSIZE, NULL);
VirtualFreeEx(hProcess, plvcolumn, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, pColumnTitle, 0, MEM_RELEASE);
CString lvcolTitle(&buf[0]);
if (lvcolTitle == _T("图像名称"))
break;
hLV = ::GetWindow(hLV, GW_HWNDNEXT);
BOOL bRet = TRUE;
CListView* pListView = (CListView*)CWnd::FromHandle(hLV);
CListCtrl& listCtrl = pListView->GetListCtrl();
int nCount = ListView_GetItemCount(hLV);
for (int i = 0; i < nCount; ++i)
LVITEM* plvitem =(LVITEM*)VirtualAllocEx(hProcess, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
TCHAR* pItemTitle = (TCHAR*)VirtualAllocEx(hProcess, NULL, TEXTSIZE, MEM_COMMIT, PAGE_READWRITE);
LV_ITEM lvi;
lvi.iSubItem = 1;
lvi.pszText = pItemTitle;
lvi.cchTextMax = TEXTSIZE;
WriteProcessMemory(hProcess, plvitem, &lvi, sizeof(LVITEM), NULL);
SendMessage(hLV, LVM_GETITEMTEXT, i, (LPARAM)plvitem);
ReadProcessMemory(hProcess, pItemTitle, buf, TEXTSIZE, NULL);
VirtualFreeEx(hProcess, plvitem, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, pItemTitle, 0, MEM_RELEASE);
CString strText(&buf[0]);
if (0 == strText.CompareNoCase(_T("缺图")))
//XXXXXXXXXXXXXXXXXXX
;
②SysTreeView32
HTREEITEM GetNextTreeItem(HWND hWnd, HTREEITEM hCurTreeItem)
if (NULL == hWnd || NULL == hCurTreeItem)
return NULL;
HTREEITEM hResultItem = TreeView_GetNextItem(hWnd, hCurTreeItem, TVGN_CHILD);
if (NULL == hResultItem)
hResultItem = TreeView_GetNextItem(hWnd, hCurTreeItem, TVGN_NEXT);
if (NULL == hResultItem)
HTREEITEM hParentItem = TreeView_GetNextItem(hWnd, hCurTreeItem, TVGN_PARENT);
hResultItem = TreeView_GetNextItem(hWnd, hParentItem, TVGN_NEXT);
return hResultItem;
void Func()
//获取树控件的内容
HWND hParent; //SysTreeView32父窗口句柄
HWND hTree = FindWindowEx(hParent, NULL, _T("SysTreeView32"), _T(""));
HWND hWnd; //主程序句柄
DWORD PID;
GetWindowThreadProcessId(hWnd, &PID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
ASSERT( NULL != hProcess);
UINT vItemCount = TreeView_GetCount(hTree);
HTREEITEM hTreeItem = TreeView_GetRoot(hTree);
TCHAR buf[MAXLENGTH];
std::vector<CString> vecItemText;
CTreeView* pTreeView = (CTreeView*)CWnd::FromHandle(hTree);
CTreeCtrl& treeCtrl = pTreeView->GetTreeCtrl();
for (int i = 0; i < vItemCount; i++)
LPTV_ITEM pTreeItem =(LPTV_ITEM)VirtualAllocEx(hProcess, NULL, sizeof(TV_ITEM), MEM_COMMIT, PAGE_READWRITE);
TCHAR* pItemText = (TCHAR*)VirtualAllocEx(hProcess, NULL, MAXLENGTH, MEM_COMMIT, PAGE_READWRITE);
TV_ITEM item;
item.mask = TVIF_TEXT;
item.hItem = hTreeItem;
item.pszText = pItemText;
item.cchTextMax = MAXLENGTH;
WriteProcessMemory(hProcess, pTreeItem, &item, sizeof(TV_ITEM), NULL);
treeCtrl.GetItem(pTreeItem);
ReadProcessMemory(hProcess, pItemText, buf, MAXLENGTH, NULL);
VirtualFreeEx(hProcess, pTreeItem, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, pItemText, 0, MEM_RELEASE);
if (TreeView_GetRoot(hTree) != hTreeItem)
CString sTreeItemText(buf);
vecItemText.push_back(sTreeItemText);
hTreeItem = GetNextTreeItem(hTree, hTreeItem);
for (auto it = vecItemText.begin(); it != vecItemText.end(); ++it)
//可根据Item内容判断转出的pdf是否可用
参考技术A 楼主有没有获取到?怎么获取的?
以上是关于使用pywinauto如何 获取systreeview32内的item(python语言)的主要内容,如果未能解决你的问题,请参考以下文章