问题描述
- 跨进程获取 Treeview的Checkbox
-
我已经用读内存的方法实现遍历Treeview获取到文本并点击了,但是要获取到是否有勾选,一直失败,求教具体方法
我是填充结构体,发送?TVM_GETITEMA消息的
解决方案
如何获取别的进程的TreeView控件的内容
如何获取别的进程的TreeView控件的内容
获取其它进程中TreeView控件的内容
解决方案二:
TVM_GETITEMSTATE
用这个消息
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773810(v=vs.85).aspx
解决方案三:
@caozhy
试了下还是一回效果都没有
Public Function GetItemCheckState(ByVal hTree As Long) As BOOL
Dim vProcessId As Long, vProcess As Long, vPointer As Long, vItemCount As Long, vTreeItem As Long
Dim i As Long, Result As Long, Bytes As Long, vItem As TVITEM, tmpItem As TVITEM
Call GetWindowThreadProcessId(hTree, vProcessId)
vProcess = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, vProcessId) '打开进程
vPointer = VirtualAllocEx(vProcess, 0&, 16, MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE) '申请内存空间
vItemCount = TreeView_GetCount(hTree) '获取Treeview Item的总数量
vTreeItem = TreeView_GetRoot(hTree) '获取第一个 Item 句柄
For i = 0 To vItemCount - 1
With vItem '填充结构
.mask = TVIF_STATE
.HItem = vTreeItem
.State = vPointer
.stateMask = TVIS_STATEIMAGEMASK
End With
Call WriteProcessMemory(vProcess, ByVal vPointer, vItem, LenB(vItem), 0&) '将填充好的结构写入内存
Result = SendMessageW(hTree, TVM_GETITEMSTATE, True, ByVal vPointer) '发送消息让目标进程将 消息内容写入申请好的内存空间
Call ReadProcessMemory(vProcess, ByVal vPointer, vItem.State, 4, 0&) '读取内存
With vItem
Debug.Print .State, (CBool(Integer_Rotate_Right(.State, 12) - 1))
End With
' TreeView_EnsureVisible hTree, vTreeItem '保证项目显示
vTreeItem = TreeNodeGetNext(hTree, vTreeItem) '获取下一个项目
Next
Call VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE)
Call CloseHandle(vProcess)
End Function
时间: 2024-11-17 19:58:46