title: Access child nodes of SysTreeView32
body: <p>This is my next question following <a href="https://stackoverflow.com/questions/17041881/hook-into-a-child-class-systreeview32-of-vbe-window">Hook into a child class SysTreeView32 of VBE window</a><br>
  <br>
  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.</p>
  
  <p>heres the code:</p>
  
  <pre><code>Option Explicit
  
  Private Const TVE_COLLAPSE = &amp;H1
  Private Const TVE_COLLAPSERESET = &amp;H8000
  Private Const TVE_EXPAND = &amp;H2
  Private Const TVE_EXPANDPARTIAL = &amp;H4000
  Private Const TVE_TOGGLE = &amp;H3
  Private Const TV_FIRST = &amp;H1100
  Private Const TVM_EXPAND = (TV_FIRST + 2)
  Private Const TVM_GETNEXTITEM = (TV_FIRST + 10)
  Private Const TVGN_ROOT = &amp;H0
  Private Const TVGN_NEXTVISIBLE = &amp;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&amp;)
     childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&amp;, 0&amp;)
     Debug.Print "childNode " &amp; childNode
  
     Do While hNode &lt;&gt; 0
        Debug.Print hNode
        varReturn = SendMessage(hWndTvw, TVM_EXPAND, TVE_COLLAPSE, hNode)
        hNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, hNode)
     Loop
  End Sub
  </code></pre>
  
  <p>and why does </p>
  
  <pre><code>childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&amp;, 0&amp;)
  Debug.Print "childNode " &amp; childNode
  </code></pre>
  
  <p>it always return 0? </p>