Jump to content



Photo

_EnumChildWindows

Enumerate List Controls Child Windows

  • Please log in to reply
4 replies to this topic

#1 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,081 posts

Posted 24 March 2010 - 08:37 PM

_EnumChildWindows
Enumerate controls/children of a Window
Posted Image


This code enumerates all controls/children of a given Window and returns them in an array.
Example code is included.

*small change 9/15/2010:
  • removed a #include line from the example code posted here (not required)
*update 3/28/2010:
  • Control ID is now retrieved. Unfortunately the indexing was reworked (sorry). But at least now I believe all the relevant information needed is retrieved.
  • Parameters to the function now have a slightly different meaning. Basically, this was done to allow searching for controls with an empty-string for a Title. All defaults are now 0, so a call can be made like this to find all Controls with a 'Button' classname:
    _EnumChildWindows($hWnd,0,0,"Button")
AutoIt         
#include <_EnumChildWindows.au3> ; =============================================================================================================================== ; <TestEnumChildWindows.au3> ; ;   Test for _EnumChildWindows UDF. ; ; Author: Ascend4nt ; =============================================================================================================================== ; =================================================================================================================== ;   TEST ; =================================================================================================================== #include <Array.au3> Local $hWnd="",$hControl="",$sTitle="",$sClass="",$aEnumList Local $iCalcPID,$hNumber1Button=-1,$hNumber4Button=-1,$hPlusButton=-1,$hEqualButton=-1 $iCalcPID=Run("calc.exe") If @error Then Exit $hWnd=WinWait("Calculator") If $hWnd=0 Then Exit ProcessClose($iCalcPID) ; Important to wait for the window to fully 'create' itself before getting child windows! ; Note that other processes that become activated somewhere between _WinWaitEx and this will cause WinWaitActive() to wait for manual activation ;WinWaitActive($hWnd)   ; bad idea in busy environment WinActivate($hWnd)  ; this seems to be a better alternative, the window seems fully created after this is called in my tests ; Parameters to function ;$hControl=HWnd(0x########) ;$sTitle="^(\d|\+|=){:content:}quot; ;$sClass="Button" $aEnumList=_EnumChildWindows($hWnd,$hControl,$sTitle,$sClass)   ;,2) for RegExp Title If @Error Then Exit ProcessClose($iCalcPID) ; Find specific items [Certain versions of Calc won't return any text] For $i=1 to $aEnumList[0][0]     Switch $aEnumList[$i][3]         Case "1"             $hNumber1Button=$aEnumList[$i][0]             ConsoleWrite("'1' Advanced Mode Name (in current state): [CLASS:Button; INSTANCE:"&$aEnumList[$i][2]&"]"&@CRLF)         Case "4"             $hNumber4Button=$aEnumList[$i][0]             ConsoleWrite("'4' Advanced Mode Name (in current state): [CLASS:Button; INSTANCE:"&$aEnumList[$i][2]&"]"&@CRLF)         Case "+"             $hPlusButton=$aEnumList[$i][0]             ConsoleWrite("'+' Advanced Mode Name (in current state): [CLASS:Button; INSTANCE:"&$aEnumList[$i][2]&"]"&@CRLF)         Case "="             $hEqualButton=$aEnumList[$i][0]             ConsoleWrite("'=' Advanced Mode Name (in current state): [CLASS:Button; INSTANCE:"&$aEnumList[$i][2]&"]"&@CRLF)     EndSwitch Next ; Add Headers $aEnumList[0][0]="Handle" $aEnumList[0][1]="Classname" $aEnumList[0][2]="Iteration" $aEnumList[0][3]="Title/Text" ; Bring the window forward WinActivate($hWnd) ; Perform a simple calculation to show interaction If $hNumber1Button<>-1 Then     ControlClick($hWnd,"",$hNumber1Button,"primary",3)     ControlClick($hWnd,"",$hNumber4Button)     Sleep(1000)     ControlClick($hWnd,"",$hPlusButton)     Sleep(1000)     ControlClick($hWnd,"",$hNumber4Button,"primary",2)  ; double click, but that's fine     Sleep(1000)     ControlClick($hWnd,"",$hEqualButton) EndIf ; And Display ALL Enumerated Windows _ArrayDisplay($aEnumList,"Enumerated controls for 'Calculator'") ProcessClose($iCalcPID)

Download the ZIP from my site


Ascend4nt's AutoIT Code License agreement:
While I provide this source code freely, if you do use the code in your projects, all I ask is that:
  • If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I credit
  • If the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)
  • The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.
  • Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.

Edited by Ascend4nt, 14 September 2011 - 02:09 AM.

  • Mongoose likes this







#2 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,081 posts

Posted 28 March 2010 - 07:59 PM

Updated :(

*update 3/28/2010:
  • Control ID is now retrieved. Unfortunately the indexing was reworked (sorry). But at least now I believe all the relevant information needed is retrieved.
  • Parameters to the function now have a slightly different meaning. Basically, this was done to allow searching for controls with an empty-string for a Title. All defaults are now 0, so a call can be made like this to find all Controls with a 'Button' classname:
    _EnumChildWindows($hWnd,0,0,"Button")


#3 cheatera

cheatera

    Seeker

  • Banned (NOT IN USE)
  • 13 posts

Posted 15 September 2010 - 08:55 AM

dude u rock.
Is There A Life BEFORE Death?im stupidSaved warn logs: cheateraSmOke_N Note Added 17 January 2009 - 02:54 PM Added to warn level Posting a way to hack the registry and force sending someones desktop via TCP. Jos Note Added 25 November 2008 - 02:52 PM Added to warn level for being an impolite rookie.once a year i go bad ... what will happen in 2010??Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)

#4 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,494 posts

Posted 15 September 2010 - 10:12 AM

Where can I find the needed include _WinWaitEx.au3 ? Posted Image
I don't find it on your website...

  AutoIt Version : 3.3.8.1/3.3.9.4 SciTE 3.3.0 Language:040C OS:WIN_7/ CPU:X64 OS:X64 

  Last updated Scripts and executables with full embedded files are available on : GoogleCode 


#5 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,081 posts

Posted 15 September 2010 - 02:52 PM

wakillon, sorry - that was a remnant from the example before it was modified. It's not required for the code to run, but I realized I left that '#include' statement in there. It's removed now, however, and should run. The code in the ZIP file on my site shouldn't have it either.

Thanks for pointing it out.





Also tagged with one or more of these keywords: Enumerate, List, Controls, Child, Windows

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users