Results 1 to 2 of 2

Thread: Spot the problem, then fix it!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    For any of you that care, I figured out a solution for myself. I created a second procedure, that loops through when called by error from the first procedure, double checking to make a full tree of parents:

    Code:
    Sub LoadTaskListChildrenErr(ByVal hwnd As Long)
    Dim Nodx As Node
              
              If GetParent(hwnd) <> 0 Then
              LoadTaskListChildrenErr GetParent(hwnd)
              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
                
    End Sub
    May I be the first to post and then repost my own solution!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width