Jump to content

List all child controls of a given window


Recommended Posts

#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
Link to comment
Share on other sites

  • 4 years later...

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 months later...

...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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...