使用pywinauto如何 获取systreeview32内的item(python语言) 15

要获取这个对话框中的买入子菜单... 要获取这个对话框中的买入子菜单 展开
 我来答
从空去听8
2017-12-31 · TA获得超过7441个赞
知道大有可为答主
回答量:6907
采纳率:93%
帮助的人:5608万
展开全部
①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是否可用
}
}
qq229596421
2020-06-01
知道答主
回答量:7
采纳率:0%
帮助的人:5121
展开全部
楼主有没有获取到?怎么获取的?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式