Using the following code:
Code:
Sub LoadTaskListChildren(ByVal hwndParent As Long, ByVal Level As Long)
        On Error Resume Next
        If Level = 0 Then
          Hwnd = hwndParent
        Else
          Hwnd = GetWindow(hwndParent, GW_CHILD)
        End If
        
        Do While Hwnd <> 0
          If GetParent(Hwnd) <> 0 Then
          Set Nodx = Form1.TreeView1.Nodes.Add("H" & GetParent(Hwnd), tvwChild, "H" & Hwnd, , MyVar)
          Else
          Set Nodx = Form1.TreeView1.Nodes.Add(, , "H" & Hwnd, , MyVar)
          End If

          LoadTaskListChildren Hwnd, Level + 1
          Hwnd = GetWindow(Hwnd, GW_HWNDNEXT)
        Loop
I removed all other uneccessary coding for clenlyness... basically it retrieves all the hwnd's of the system and adds them to a list. Each item is made a child of the item that owns it, just like in the operating system. However, when error handling is enabled, some child windows are trying to be added to parents that don't exist...

Why is this happening? In the debugger, I tried LoadTastListChildren GetParent(Hwnd), Level - 1 to restore the order, but that never seems to work. Looping the entire process through twice still leaves some handles out.