GetWindows - How to get all child windows at all levels from an application?

Mateus

Active member
Joined
Apr 16, 2010
Messages
27
Programming Experience
3-5
Hi,
I'm trying to get all the child windows for an application (inc. child of child) but I'm getting really confused using GetWindows and loops as it's only returning the first level of child windows. I'm sure I'm just been a total dunce :drunk: there must be a simply solution. Current code...
VB.NET:
        lHwndDesktop = GetDesktopWindow()
        lHwndParent = GetWindow(lHwndDesktop, GW_CHILD)
        Do While lHwndParent.ToInt32 > 0
            GetClassName(lHwndParent, sFoundClassName, sFoundClassName.Capacity)
            If sFoundClassName.ToString.Trim = "WindowsForms10.Window.8.app.0.218f99c" Then
                lHwndChild = GetWindow(lHwndParent, GW_CHILD)
                Do While lHwndChild.ToInt32 > 0
                    GetWindowText(lHwndChild, sWindowTitle, 255)
                    MsgBox(sWindowTitle.ToString.Trim)
                    lHwndChild = GetWindow(lHwndChild, GW_HWNDNEXT)
                Loop
            End If
            lHwndParent = GetWindow(lHwndParent, GW_HWNDNEXT)
        Loop
Many thanks,
M
 
Never mind, I've just created nested 'Do While' loops which run up and down an array.

e.g:
VB.NET:
lHwndArray(3) = GetWindow(lHwndArray(2), GW_CHILD)
 
GetWindow function (Windows)
The EnumChildWindows function is more reliable than calling GetWindow in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed.
 
Back
Top