SysTreeView32的访问子节点 [英] Access child nodes of SysTreeView32
问题描述
这是我的下一个问题<一href=\"http://stackoverflow.com/questions/17041881/hook-into-a-child-class-systreeview32-of-vbe-window\">Hook进入VBE窗口结果子类SysTreeView32
结果
我现在可以访问SysTreeView32,但我不能访问HNODE的子节点。我已经尝试了许多变化,并一直念叨它在近2个小时,但我不能工作了。这甚至可能?我真的想避免因不同的窗口尺寸和位置,但如果多数民众赞成的唯一途径mouse_event并单击然后我会尽量实施。
This is my next question following Hook into a child class SysTreeView32 of VBE window
I can access the SysTreeView32 now but I cant access the child node of the hNode. I have tried many variations and been reading about it for the past 2 hours but I can't work it out. Is this even possible? I really want to avoid the mouse_event and clicking because of different window dimensions and position but if thats the only way then I will try to implement that.
继承人的code:
Option Explicit
Private Const TVE_COLLAPSE = &H1
Private Const TVE_COLLAPSERESET = &H8000
Private Const TVE_EXPAND = &H2
Private Const TVE_EXPANDPARTIAL = &H4000
Private Const TVE_TOGGLE = &H3
Private Const TV_FIRST = &H1100
Private Const TVM_EXPAND = (TV_FIRST + 2)
Private Const TVM_GETNEXTITEM = (TV_FIRST + 10)
Private Const TVGN_ROOT = &H0
Private Const TVGN_NEXTVISIBLE = &H6
Private Const TVGN_CHILD = 4
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Sub CollapseProjects()
Dim hWndVBE As Long, hWndPE As Long, hWndTvw As Long, hNode As Long, varReturn
hWndVBE = FindWindowEx(0, 0, "wndclass_desked_gsk", Application.VBE.MainWindow.Caption)
hWndPE = FindWindowEx(hWndVBE, 0, "PROJECT", vbNullString)
hWndTvw = FindWindowEx(hWndPE, 0, "SysTreeView32", vbNullString)
Dim childNode As Long
hNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_ROOT, 0&)
childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&)
Debug.Print "childNode " & childNode
Do While hNode <> 0
Debug.Print hNode
varReturn = SendMessage(hWndTvw, TVM_EXPAND, TVE_COLLAPSE, hNode)
hNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, hNode)
Loop
End Sub
和为什么
childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&)
Debug.Print "childNode " & childNode
它总是返回0?
it always return 0?
推荐答案
这
childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&)
是不是要求一个子节点。首先,你将消息发送到 HNODE
,没有树的控制,这使得没有任何意义。然后,让孩子节点,您需要通过 TVGN_CHILD
标志,它是为0x4,在的wParam
。您还需要通过你想要的子项 lParam的
。
Is not asking for a child node. Firstly, you're sending the message to hNode
, not the tree control, which makes no sense at all. Then, to get the child node, you need to pass the TVGN_CHILD
flag, which is 0x4, in wParam
. You also need to pass the item you want the child of in lParam
.
因此,它可能会是这个样子:
So it would probably look something like this:
childNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_CHILD, hNode)
查看文档为 TVM_GETNEXTITEM
消息,以了解更多信息。
See the docs for the TVM_GETNEXTITEM
message for more information.
这篇关于SysTreeView32的访问子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!