这是Hook into a child class SysTreeView32 of VBE window之后的下一个问题
我现在可以访问SysTreeView32,但我无法访问hNode的子节点。我已经尝试了很多变化,并且在过去2小时内一直在阅读它,但我无法解决它。这甚至可能吗?我真的想避免使用mouse_event并点击,因为不同的窗口尺寸和位置,但如果这是唯一的方法,那么我将尝试实现它。
继承人代码:
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?
答案 0 :(得分:1)
此:
childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&)
不要求子节点。首先,您将消息发送到hNode
,而不是树控件,这根本没有意义。然后,要获取子节点,需要在TVGN_CHILD
中传递wParam
标志,即0x4。您还需要在lParam
中传递您想要孩子的项目。
所以它可能看起来像这样:
childNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_CHILD, hNode)
有关详情,请参阅docs TVM_GETNEXTITEM
消息。