Access SysTreeView32 Child Nodes

This is my next question, next to Including a VBE Window in a SysTreeView32 Child Class

Now I can access SysTreeView32, but I can not access the child node hNode. I tried many variations and read about it for the last 2 hours, but I canโ€™t solve it. Is it possible? I really want to avoid mouse_event and click due to the different sizes and position of the window, but if this is the only way, I will try to implement this.

the code looks like:

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 

and why

 childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&) Debug.Print "childNode " & childNode 

Does it always return 0?

+3
source share
1 answer

It:

 childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&) 

Does not request a child node. Firstly, you are sending a message to hNode , not to the tree control, which makes no sense. Then, to get the child of the node, you need to pass the flag TVGN_CHILD , which is 0x4, to wParam . You also need to pass the element in which you want to have an lParam child.

So this will probably look something like this:

 childNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_CHILD, hNode) 

See the docs for the TVM_GETNEXTITEM message for more information.

+1
source

All Articles