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

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

    • TommyDDR
      By TommyDDR
      Hi,
      I have to set a resizing mode to differents controls in a hidden gui, that gui is initialised (hidden) and resized by a WinMove.
      But when i show it, control are not resized where thez should.
      There is a simple code that reproduce the problem.
      Same gui, same content, one displayed then moved, the other moved then displayed :
      #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $gui[2] Global $labels[2] Global $taille[2] = [200, 100] For $i = 0 To UBound($gui, 1) - 1 $gui[$i] = GUICreate($i, $taille[0], $taille[1], $i * ($taille[0]+100) + 500, (@DesktopHeight-$taille[1])/2) GUISetOnEvent($GUI_EVENT_CLOSE, "quit", $gui) $labels[$i] = GUICtrlCreateLabel("Test resizing...", $taille[0]-105, $taille[1]-25, 100, 20) GUICtrlSetBkColor($labels[$i], 0xE0E0E0) GUICtrlSetResizing($labels[$i], BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH, $GUI_DOCKHEIGHT)) Next GUISetState(@SW_SHOW, $gui[0]) For $i = 0 To UBound($gui, 1) - 1 WinMove($gui[$i], "", Default, Default, $taille[0]+100, $taille[1]+100) Next GUISetState(@SW_SHOW, $gui[1]) While(True) Sleep(10) WEnd Func quit() Exit EndFunc Is that a bug or do miss i something ?
      EDIT : This bug disapear if gui is shown at lease one time (even if hide then)
    • echoAwoo
      By echoAwoo
      SOLVED
      Basically, my script needed a conditional assignment to a variable. It needed to check if the size of the array was valid before assigning any value to the variable.
       
       


      So I've got a data entry task that I've been trying to automate. I actually have the script running, it cycles, draws it's necessary arrays, etc. But it will only cycle up to count #22, 23+ do not work.
      THE GIST
      I have two excel documents that I draw the data from. $aWO array has values from one of these documents. The instructions to draw these are under _at_wo().
      This function feeds into another function to compare a derived value from the first file and request it's corresponding value. In order to do this, I used _Excel_RangeFind() (had to comment out the Cell Name and Cell Comment aspects of that function in order for it to work at all.) Then I pull the address information from array $aTracking[0][2], swap the column from A to B, and it works beautifully. 
      Then cycle 23 happens, and then $aTracking[0][2] reports as out of range. Why? 
       
      Here's the code. Error reported from line #70. This array call works on loops 1-22 ($iCount value 0-21)
      http://pastebin.com/Bd5v6Dbc
    • Simpel
      By Simpel
      Hi,
      I updated to the last version. Since then a lot of functions are not working.  For instance expanding abbreviation. My au3abbrev.properties are correct and abbrev.properties are including both import lines. The abbreviation is red but won't expand. Neither with space nor Ctrl+B.
      Debug to msgbox and console not working, list functions, jump to function, open include too.
      SciTE Jump works. Block and box comment too.
      I have the feeling all functions especially for autoit are not working.
      Any help? Regards, Conrad