Access child nodes of SysTreeView32
Asked Answered
S

1

3

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.

heres the 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

and why does

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

it always return 0?

Skin answered 11/6, 2013 at 12:18 Comment(0)
C
1

This:

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

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)

See the docs for the TVM_GETNEXTITEM message for more information.

Correia answered 11/6, 2013 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.