Sign in to follow this  
Followers 0
ExpertNoob

List all child controls of a given window

6 posts in this topic

How to list all child controls of a given window/GUI?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <Array.au3>
#include <Constants.au3>
#include <WinAPI.au3>

Global $avChildren

Run('calc.exe')
WinWaitActive('Calculator')

$hWnd = WinGetHandle('Calculator')
WinListChildren($hWnd, $avChildren)

_ArrayDisplay($avChildren)
Exit


Func WinListChildren($hWnd, ByRef $avArr)
    If UBound($avArr, 0) <> 2 Then
        Local $avTmp[10][2] = [[0]]
        $avArr = $avTmp
    EndIf
    
    Local $hChild = _WinAPI_GetWindow($hWnd, $GW_CHILD)
    
    While $hChild
        If $avArr[0][0]+1 > UBound($avArr, 1)-1 Then ReDim $avArr[$avArr[0][0]+10][2]
        $avArr[$avArr[0][0]+1][0] = $hChild
        $avArr[$avArr[0][0]+1][1] = _WinAPI_GetWindowText($hChild)
        $avArr[0][0] += 1
        WinListChildren($hChild, $avArr)
        $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
    WEnd
    
    ReDim $avArr[$avArr[0][0]+1][2]
EndFunc

Don't list all child controls of me :)

Edited by Authenticity
1 person likes this

Share this post


Link to post
Share on other sites

Exactly what I needed!

Thank you Authenticity :)

Share this post


Link to post
Share on other sites

I have multiple IE windows with file select dialogues open, and trying to determine which open file dialogue goes to which IE window

That script outputs a lot of handles, which is cool, and I Can get the handle of the window using Au3InfoTool, but the handle of the dialogue does not appear on the list of children the script generates :( help?

Or would it be easier to determine the  child's parent window?


0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Alright, so looking backwards for the parent works rather well :D

although this makes sense, usually things only have a couple parents.. :P

Func _IE_GetFileSelectWindow($hIE)
    for $i = 1 to 99999
        $child = WinGetHandle("[CLASS:#32770; INSTANCE:"&$i&"]","")
        if @error and $i > 10 then return 0
        $parent = _WinAPI_GetParent($child)
        If $parent = $hIE Then Return $child
    Next
EndFunc 

Code, for anyone who would like it. might come in useful :P

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

...and I'm back! While looking backwards from the child for the parent works on older IE versions, the new IE10 seems to break this :/. How can a child window not have $oIE as it's parent?
 

I've tried using your sample a few posts up to list the children, and check if the handle of the dialog is on that list, but it isn't. Any ideas?

#include <IE.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <Constants.au3>

;go to google.com, go to images, click upload an image, click browse
;this should give you a nice file upload box you can test on

$oIE = _IEAttach("Google Images")
$hWnd = _IEPropertyGet($oIE, "hwnd")
Global $avChildren

WinListChildren($hWnd, $avChildren)
_ArrayDisplay($avChildren)
Exit


Func WinListChildren($hWnd, ByRef $avArr)
    If UBound($avArr, 0) <> 2 Then
        Local $avTmp[10][2] = [[0]]
        $avArr = $avTmp
    EndIf

    Local $hChild = _WinAPI_GetWindow($hWnd, $GW_CHILD)

    While $hChild
        If $avArr[0][0]+1 > UBound($avArr, 1)-1 Then ReDim $avArr[$avArr[0][0]+10][2]
        $avArr[$avArr[0][0]+1][0] = $hChild
        $avArr[$avArr[0][0]+1][1] = _WinAPI_GetWindowText($hChild)
        $avArr[0][0] += 1
        WinListChildren($hChild, $avArr)
        $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
    WEnd

    ReDim $avArr[$avArr[0][0]+1][2]
EndFunc

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0