Sign in to follow this  
Followers 0
Ascend4nt

_EnumChildWindows

5 posts in this topic

#1 ·  Posted (edited)

_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")

#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
1 person likes this

Share this post


Link to post
Share on other sites

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")

Share this post


Link to post
Share on other sites

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??[u]Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)[/u]

Share this post


Link to post
Share on other sites

Where can I find the needed include _WinWaitEx.au3 ? Posted Image

I don't find it on your website...


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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.

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

  • Similar Content

    • Ascer
      By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1 - 4.5 (on this version Microsoft destroy old rules) System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
    • nacerbaaziz
      By nacerbaaziz
      can we  create a list box with  Columns?
      welcome everybody
      Dears I have a question if you let me
      can we  create a list box with  Columns?
      i know we can create a list view with Columns
      but my question is about the list box
      I'm waiting your responses
      Thank you in advance
    • XaelloNegative
      By XaelloNegative
      Hi,
      I'm currently saving process time stamps of my employer's other employees and saving it in a text document as data storage. However, my employer wants it to be processed in a day to day basis to generate their average process time per day. How can I compare today from yesterday and so on and so forth with the succeeding days? Whats the best approach to this?
      Thank you.
      ~XN~
    • mdwerne
      By mdwerne
      Hello,
      I'm working on a script that writes detailed application event logs, and I'd like to know if there is a way with Autoit to write multiple lines of XML EventData (see example below):
      <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Application" /> <EventID Qualifiers="0">1001</EventID> <Level>4</Level> <Task>0</Task> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2015-07-12T21:26:07.000000000Z" /> <EventRecordID>86554</EventRecordID> <Channel>Application</Channel> <Computer>YOUR_COMPUTER</Computer> <Security /> </System> <EventData> <Data>DeskTop Agent: Mike</Data> <Data>Observer Username: Miguel</Data> etc... </EventData> </Event> So far, using EventCreate, everything I send end's up in a single <data> entry (see below):
      <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Application" /> <EventID Qualifiers="0">1001</EventID> <Level>4</Level> <Task>0</Task> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2015-07-12T21:26:07.000000000Z" /> <EventRecordID>86554</EventRecordID> <Channel>Application</Channel> <Computer>YOUR_COMPUTER</Computer> <Security /> </System> <EventData> <Data>DeskTop Agent: Mike Observer Username: Miguel</Data> </EventData> </Event> Here is the code I'm using thus far (which does not work the way I'd like):
      $LogData = @CRLF & "DeskTop Agent: " & @UserName & @CRLF & "Observer Username: " & $DTObserver & @CRLF & "File name/s with extension: " & $FilenameWextension & @CRLF & "Action Performed: " & $ActionPerformed & @CRLF & "Explanation: " & $Explanation & @CRLF & "Machine Name: " & @ComputerName & @CRLF & "IP Address: " & @IPAddress1 & @CRLF & "App1Installed: " & $App1 & @CRLF & "App2Installed: " & $App2 Run("eventcreate /T Information /ID 100 /L Application /SO DTALog /D " & Chr(34) & "DTALog Details: " & $LogData & Chr(34), "", @SW_HIDE, 2) I found a Stackoverflow post that talks about doing it in C# (https://stackoverflow.com/questions/7694276/how-to-add-multiple-lines-of-eventdata-to-an-eventlog-in-windows)
      but I'd like to determine if it can be accomplished with AutoIt!.
      Thanks for your time,
      -Mike
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      i am working on a application where if the flashing is success i get a window saying "SUCCESS" and if the flashing failed a window saying "FAILED" and i have to automatically identify pass or fail.the problem is both the windows are having the same control ID. how can i differentiate between both windows? so that i can make use of that in script for automation///
       
       
      Thanks