Sign in to follow this  
Followers 0
Mechaflash

Function to enumerate controls?

8 posts in this topic

#1 ·  Posted (edited)

Anyway to easily enumerate all controls (i.e. control classes, instances, etc.) in a 3rd party app?

A business app I'm working on has all of the controls with their own classes and correct instances, but I don't know of an easy way to target each control in a loop without manually inputting the control info.

Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites



Something like this loop for each class? Else, would you re-explain?

#include <Array.au3>
$iArrayCounter = 1
Dim $aControls[$iArrayCounter][3]
Dim $aControlTypes[3]=["Edit","Button","etc"]
For $i = 0 To Ubound ($aControlTypes)-1
 $iInstance = 1
 While 1
  $hControl = ControlGetHandle("DevTrack", "", "[CLASSNN:" & $aControlTypes[$i] & $iInstance & "]")
  If IsHWnd ( $hControl ) Then
   ReDim $aControls[$iArrayCounter][3]
   $aControls[$iArrayCounter-1][0]=$aControlTypes[$i]
   $aControls[$iArrayCounter-1][1]=$iInstance
   $aControls[$iArrayCounter-1][2]=$hControl
   $iArrayCounter += 1
  Else
   ExitLoop
  EndIf
  $iInstance += 1
 WEnd
Next
_ArrayDisplay ($aControls)

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Something like this loop for each class? Else, would you re-explain?

#include <Array.au3>
$iArrayCounter = 1
Dim $aControls[$iArrayCounter][3]
Dim $aControlTypes[3]=["Edit","Button","etc"]
For $i = 0 To Ubound ($aControlTypes)-1
$iInstance = 1
While 1
$hControl = ControlGetHandle("DevTrack", "", "[CLASSNN:" & $aControlTypes[$i] & $iInstance & "]")
If IsHWnd ( $hControl ) Then
ReDim $aControls[$iArrayCounter][3]
$aControls[$iArrayCounter-1][0]=$aControlTypes[$i]
$aControls[$iArrayCounter-1][1]=$iInstance
$aControls[$iArrayCounter-1][2]=$hControl
$iArrayCounter += 1
Else
ExitLoop
EndIf
$iInstance += 1
WEnd
Next
_ArrayDisplay ($aControls)

Now if that could be modified to automatically find out what the classes are without specifying them, that would be what I was looking for.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Find me a way to get HWND -> Class, and I can do just that, using something like:

ControlGetHandle("Yourwindow", "", "[REGEXPCLASS:" & $aControlTypes[$i] & "; INSTANCE:" & $iInstance & "]")

aaaaand, possibly found it:

Func GetClassName($hWnd)

$Rt = DllCall("User32.dll","int","GetClassNameW","HWND",$hWnd,"wstr","","int",5000)

if @error Or $Rt[0] = 0 Then Return SetError(1,0,0)

Return SetError(0,0,$Rt[2])

EndFunc

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Your welcome :)

$iArrayCounter = 1
Dim $aControls[$iArrayCounter][3]
Dim $aControlTypes[3]=["Edit","Button","etc"]
Dim $aControlTypes[1]=["[Ww]+"]
For $i = 0 To Ubound ($aControlTypes)-1
$iInstance = 1
While 1 ; loop through all instances
$sRegExp = $aControlTypes[0]
$hControl = ControlGetHandle("DevTrack", "", "[REGEXPCLASS:" & $sRegExp & "; INSTANCE:" & $iInstance & "]")
If Not IsHWnd ( $hControl ) Then ExitLoop
While 1; loop through all class types within each instance
$hControl = ControlGetHandle("DevTrack", "", "[REGEXPCLASS:" & $sRegExp & "; INSTANCE:" & $iInstance & "]")
If IsHWnd ( $hControl ) Then
    $sControlType = GetClassName($hControl)
    $sRegExp = $sRegExp & "[^" & $sControlType & "]"
    ReDim $aControls[$iArrayCounter][3]
    $aControls[$iArrayCounter-1][0]=$sControlType
    $aControls[$iArrayCounter-1][1]=$iInstance
    $aControls[$iArrayCounter-1][2]=$hControl
    $iArrayCounter += 1
Else
    ExitLoop
EndIf
WEnd
$iInstance += 1
WEnd
Next
_ArrayDisplay ($aControls)
Func GetClassName($hWnd)
$Rt = DllCall("User32.dll","int","GetClassNameW","HWND",$hWnd,"wstr","","int",5000)
if @error Or $Rt[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,$Rt[2])
EndFunc

edit: almost, some itteration issues

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Simplified...got all the control types, then used my original loop:

#include <Array.au3>
$iArrayCounter = 1
Dim $aControls[$iArrayCounter][3]
Dim $aControlTypes[1]
$sRegExp = ""
; get all classes
While 1; loop through all class types within each instance
 $hControl = ControlGetHandle("DevTrack", "", "[REGEXPCLASS:" & $sRegExp & "]")
 If IsHWnd($hControl) Then
  $sControlType = GetClassName($hControl)
  If $iArrayCounter > 1 Then
   $sRegExp = StringLeft($sRegExp, StringLen($sRegExp) - 1)
   $sRegExp = $sRegExp & "|^" & $sControlType & "]"
  Else
   $sRegExp = "[^" & $sControlType & "]"
  EndIf
  ConsoleWrite ( $sRegExp & @CRLF )
  ReDim $aControlTypes[$iArrayCounter]
  $aControlTypes[$iArrayCounter - 1] = $sControlType
  $iArrayCounter += 1
  ConsoleWrite ( $sControlType & @CRLF )
 Else
  ExitLoop
 EndIf
WEnd
$iArrayCounter = 1
Dim $aControls[$iArrayCounter][3]
For $i = 0 To Ubound ($aControlTypes)-1
 $iInstance = 1
 While 1
  $hControl = ControlGetHandle("DevTrack", "", "[CLASSNN:" & $aControlTypes[$i] & $iInstance & "]")
  If IsHWnd ( $hControl ) Then
   ReDim $aControls[$iArrayCounter][3]
   $aControls[$iArrayCounter-1][0]=$aControlTypes[$i]
   $aControls[$iArrayCounter-1][1]=$iInstance
   $aControls[$iArrayCounter-1][2]=$hControl
   $iArrayCounter += 1
  Else
   ExitLoop
  EndIf
  $iInstance += 1
 WEnd
Next
_ArrayDisplay ( $aControls )
Func GetClassName($hWnd)
 $Rt = DllCall("User32.dll", "int", "GetClassNameW", "HWND", $hWnd, "wstr", "", "int", 5000)
 If @error Or $Rt[0] = 0 Then Return SetError(1, 0, 0)
 Return SetError(0, 0, $Rt[2])
EndFunc   ;==>GetClassName
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

sweeeeeeeet. Works uber great. Now go make this a UDF and share your brilliance :thumbsup:

Thanx JD


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Adjusted to be called as a function with example usage.

#include <Array.au3>
Local $hWnd
$hWnd = WinGetHandle("All My Papers Demonstration Software")
$aControlClasses = _WinControls_Enumerate($hWnd)
_ArrayDisplay($aControlClasses)

Func _WinControls_Enumerate(Const $hWinHandle) ; Pass a window handle to this function. Outputs a 2D-3Index array of control Classes, Instances, and Handles of a window
    Local $iArrayCounter = 1, $sRegExp = "", $sWinHandle
    Dim $aControls[$iArrayCounter][3]
    Dim $aControlTypes[1]

    ; get all classes
    While 1; loop through all class types within each instance
        $hControl = ControlGetHandle($hWinHandle, "", "[REGEXPCLASS:" & $sRegExp & "]")
        If IsHWnd($hControl) Then
            $sControlType = GetClassName($hControl)
            If $iArrayCounter > 1 Then
                $sRegExp = StringLeft($sRegExp, StringLen($sRegExp) - 1)
                $sRegExp = $sRegExp & "|^" & $sControlType & "]"
            Else
                $sRegExp = "[^" & $sControlType & "]"
            EndIf
            ConsoleWrite ( $sRegExp & @CRLF )
            ReDim $aControlTypes[$iArrayCounter]
            $aControlTypes[$iArrayCounter - 1] = $sControlType
            $iArrayCounter += 1
            ConsoleWrite ( $sControlType & @CRLF )
            Else
            ExitLoop
        EndIf
    WEnd
    $iArrayCounter = 1
    Dim $aControls[$iArrayCounter][3]
    For $i = 0 To Ubound ($aControlTypes)-1
        $iInstance = 1
        While 1
            $hControl = ControlGetHandle($hWinHandle, "", "[CLASSNN:" & $aControlTypes[$i] & $iInstance & "]")
            If IsHWnd ( $hControl ) Then
                ReDim $aControls[$iArrayCounter][3]
                $aControls[$iArrayCounter-1][0]=$aControlTypes[$i]
                $aControls[$iArrayCounter-1][1]=$iInstance
                $aControls[$iArrayCounter-1][2]=$hControl
                $iArrayCounter += 1
            Else
                ExitLoop
            EndIf
            $iInstance += 1
        WEnd
    Next
    Return $aControls
EndFunc

    Func GetClassName($hWnd)
        $Rt = DllCall("User32.dll", "int", "GetClassNameW", "HWND", $hWnd, "wstr", "", "int", 5000)
        If @error Or $Rt[0] = 0 Then Return SetError(1, 0, 0)
        Return SetError(0, 0, $Rt[2])
    EndFunc   ;==>GetClassName

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

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

    • CodingMonkey81
      By CodingMonkey81
      All,
      I'm working on automating the update process for a piece of software that we use at my company. The installer file always contains the version number as a part of the file name (eg InstallFile_9342.msi) and the numbers always change with every update.
      How do I use AutoIt to run the program? I know I can't use a wildcard in place of the numbers when using the "Run" command. 
      I tried 
      Local $aArray = _FileListToArray("C:\path\to\file", "InstallFile_*.msi", 0, 1) Run("$aArray") and I also tried
      Local $bInstall = FileFindFirstFile("InstallFile_*.msi") Run("$bInstall") and neither worked. 
      Can someone please point me in the right direction? I've done some searching on the forum and haven't found anyone in a similar situation before.
      Thanks!
    • RHolmes
      By RHolmes
      I have a program that has a control that changes color a few seconds into running. So ideally, I would poll this to tell when an event has occurred. 
      I can't seem to retrieve the correct color value for a control. It always seems to return white indicating that its selecting somewhere else in the window.
      In the PixelGetColor call I'm adding half the width to the x value and subtracting half the height to the y value  in order to get the center of the control. (assuming the coords returned by ControlGetPos are top left - which i can't be sure of) But I've also tried without modifying the x/y and with changing the PixelCoordMode option to 2. Maybe I'm making a silly mistake and can't see it? Any help would be appreciated.
      Code is below:
      Opt("PixelCoordMode", 0)
      FileChangeDir( "C:\Where\My\File\Is" );
      Run( "MyProgram.exe" )
      Local $hClient = WinWaitActive( $CLIENT_TITLE, "", 10 )
      Local $systemIndicatorClassNN= "[CLASS:Qt5QWindowIcon; INSTANCE:99]"
      Local $hSystemIndicator = ControlGetHandle ( $hClient, "", $systemIndicatorClassNN)
      Local $xywh = ControlGetPos ( $hClient, "", $hSystemIndicator )
      For $i = 10 To 1 Step -1
            $color = PixelGetColor ( $xywh[0] + ($xywh[2]/2), $xywh[1] - ($xywh[3]/2), $hClient )
            LogToFile( $color )
            Sleep( 2000 )
      Next
    • VAN0
      By VAN0
      Hello.
      I have a program XX that asks for user confirmation on exit, which hangs the system reboot/shutdown process until I confirm. So I decided create a autoit script that would automatically close that dialog and let the system reboot/shutdown.
      The problem I'm facing is that my scripts now exits before the XX.
      Is there a way delay script exit until the XX is closed but only when system is rebooting/shutting down?
       
      Thank you.
    • Simpel
      By Simpel
      Hi, I created a gui with date field but formatted as time in HH:mm. It always shows "now-time". Even if I try to set it with GUICtrlSetData.
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm" ; Just display hours and minutes <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUICtrlSetData($idDate, "00:00") ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example How can I set the time field with another time and how can this field be set blank?
      Regards, Conrad
    • hunte922
      By hunte922
      Edit: The solution! Maybe?
       
      I need to download an image from a website using AutoIt but the download, when viewed in a text editor, does not appear to be the same as if I had downloaded it from a web browser.
      Could anyone help me figure out why this is happening?
      I've already tried _INetGetSource, InetGet, _IENavigate, wget, this, and a few .bat and .vbs scripts.
       
      Example Code:
      #include <Inet.au3> Local $source = _INetGetSource("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a") Local $newfile = FileOpen(@ScriptDir & "\test.txt", 2) FileWrite($newfile, $source) FileClose($newfile) Image URL: http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a
      Screenshot attached.