Jump to content

Recommended Posts

Posted

Very well written code. Great.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Very Nice

But I notice that [msctls_statusbar321] get text only from first element.

Cheers.

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Great job jdelaney !

I made a similar script (without any filter), posted in the french forum : http://www.autoitscript.fr/forum/viewtopic.php?p=74100#p74100

Have a look to it : I used the RegExp method to avoid the use of Array.au3

  • 3 months later...
Posted (edited)

Hello,

I have an application that has dynamic window controlID's, so that each time I close and reopen the application the controlID has changed and my AutoIT script no longer works.

Is there a way to write a script that can find out what the controlID is and then have it run into the already existing script automatically?

 
Run('C:Program FilesmyCompanymyApplicationFoldertheApplication.exe')
 
_WinWaitActivate("Window ","text ")
 
WinActivate("Window ","text ")
 
ControlTreeView("Window ", "", 459938, "Expand")
Sleep(1500)
 
ControlTreeView("Window ", "", 459938, "Collapse")
Sleep(1500)
Edited by jreedmx
  • Moderators
Posted (edited)

Yep, that happens, the code wasn't meant to be ran, just to point out the obvious.

Edit:

I fixed it, it was just a line feed issue.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted
  On 1/6/2015 at 8:58 PM, jguinch said:

@jreedmx : did you try jdelaney's code with your app ? What is the result ?

Thanks for your response @jquinch

When I run jdelaney's code I get the following data for the current dynamic controlID (which in this instance is 9306824):

Func=[GetAllWindowsControls]: ControlCounter=[ 18] ControlID=[9306824] Handle=[0x008E02C8] ClassNN=[WindowsForms10.SysTreeView32.app.0.fcf9a41] XPos=[-9990] YPos=[-9938] Width=[ 469] Height=[ 202] IsVisible=[0] Text=[].

  • 1 year later...
Posted (edited)

Recently I was in need to use this function.
I had to change it a little, it may be useful to someone.

Little refactored function:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#include <Array.au3>
#include <WinAPI.au3>

_Example()
Func _Example()
    MsgBox(0, "Make your window active!" , 'This Message Box will be closed in 5 seconds', 5)

    Local $sControlText = GetAllWindowsControls(WinGetHandle("[ACTIVE]"))
    ClipPut($sControlText)
    ConsoleWrite($sControlText)
EndFunc   ;==>_Example


; #FUNCTION# ====================================================================================================================
; Name ..........: GetAllWindowsControls
; Description ...:
; Syntax ........: GetAllWindowsControls($hCallersWindow[, $bOnlyVisible = Default[, $sStringIncludes = Default[, $sClass = Default]]])
; Parameters ....: $hCallersWindow      - a handle value.
;                  $bOnlyVisible        - [optional] a boolean value. Default is Default.
;                  $sStringIncludes     - [optional] a string value. Default is Default.
;                  $sClass              - [optional] a string value. Default is Default.
; Return values .: String with Controls descriptions.
; Author ........: jdelaney
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........: https://www.autoitscript.com/forum/topic/164226-get-all-windows-controls/
; Example .......: No
; ===============================================================================================================================
Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible = Default, $sStringIncludes = Default, $sClass = Default)
    If Not IsHWnd($hCallersWindow) Then
        ConsoleWrite("$hCallersWindow must be a handle...provided=[" & $hCallersWindow & "]" & @CRLF)
        Return False
    EndIf

    ; Get all list of controls
    If $bOnlyVisible = Default Then $bOnlyVisible = False
    If $sStringIncludes = Default Then $sStringIncludes = ""
    If $sClass = Default Then $sClass = ""

    Local $sClassList = WinGetClassList($hCallersWindow)

    ; Create array
    Local $aClassList = StringSplit($sClassList, @CRLF, 2)

    ; Sort array
    _ArraySort($aClassList)
    _ArrayDelete($aClassList, 0)

    ; Loop
    Local $iCurrentClass = ""
    Local $iCurrentCount = 1
    Local $iTotalCounter = 1

    If StringLen($sClass) > 0 Then
        For $i = UBound($aClassList) - 1 To 0 Step -1
            If $aClassList[$i] <> $sClass Then
                _ArrayDelete($aClassList, $i)
            EndIf
        Next
    EndIf

    Local $hControl = Null, $aControlPos
    Local $sControlText = ''
    Local $iControlID = 0
    Local $bIsVisible = False
    Local $sResult = ''

    For $iClass_idx = 0 To UBound($aClassList) - 1
        If $aClassList[$iClass_idx] = $iCurrentClass Then
            $iCurrentCount += 1
        Else
            $iCurrentClass = $aClassList[$iClass_idx]
            $iCurrentCount = 1
        EndIf

        $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]")
        $sControlText = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}")
        $aControlPos = ControlGetPos($hCallersWindow, "", $hControl)
        $iControlID = _WinAPI_GetDlgCtrlID($hControl)
        $bIsVisible = ControlCommand($hCallersWindow, "", $hControl, "IsVisible")
        If $bOnlyVisible And Not $bIsVisible Then
            $iTotalCounter += 1
            ContinueLoop
        EndIf

        If StringLen($sStringIncludes) > 0 Then
            If Not StringInStr($sControlText, $sStringIncludes) Then
                $iTotalCounter += 1
                ContinueLoop
            EndIf
        EndIf

        If IsArray($aControlPos) Then
            $sResult &= "Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $iControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aControlPos[0]) & "] YPos=[" & StringFormat("%4s", $aControlPos[1]) & "] Width=[" & StringFormat("%4s", $aControlPos[2]) & "] Height=[" & StringFormat("%4s", $aControlPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $sControlText & "]." & @CRLF
        Else
            $sResult &= "Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $iControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $sControlText & "]." & @CRLF
        EndIf

        If Not WinExists($hCallersWindow) Then ExitLoop
        $iTotalCounter += 1
    Next
    Return $sResult
EndFunc   ;==>GetAllWindowsControls

Regards,

mLipok

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 years later...
Posted

Hi jdelaney,

I am new to AutoIT and unable to figure out how to set a radio button checked, which is within a Groupbox. The AutoIt v3 Window Info tool doesn't provide information within a Groupbox. Hence, I am trying to use your code as is to compile and generate an exe out of it. When I copied your code and why a syntax error is thrown when I try to use your code as is. It reports an error as shown below

(10, 1)  : error: syntax error (illegal character)

Am I missing something? Could you please help me?

Posted

I copied your code and was trying to compile/build/syntaxcheck prod

#include <Array.au3>
#include <WinAPI.au3>
ConsoleWrite("Make your window active!" & @CRLF)
Sleep(5000)
GetAllWindowsControls(WinGetHandle("[ACTIVE]"))
Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible=Default, $sStringIncludes=Default, $sClass=Default)
    If Not IsHWnd($hCallersWindow) Then
        ConsoleWrite("$hCallersWindow must be a handle...provided=[" & $hCallersWindow & "]" & @CRLF)
        Return False
    EndIf
    ; Get all list of controls
    If $bOnlyVisible = Default Then $bOnlyVisible = False
    If $sStringIncludes = Default Then $sStringIncludes = ""
    If $sClass = Default Then $sClass = ""
    $sClassList = WinGetClassList($hCallersWindow)
    ; Create array
    $aClassList = StringSplit($sClassList, @CRLF, 2)
    ; Sort array
    _ArraySort($aClassList)
    _ArrayDelete($aClassList, 0)
    ; Loop
    $iCurrentClass = ""
    $iCurrentCount = 1
    $iTotalCounter = 1
    If StringLen($sClass)>0 Then
        For $i = UBound($aClassList)-1 To 0 Step - 1
            If $aClassList[$i]<>$sClass Then
                _ArrayDelete($aClassList,$i)
            EndIf
        Next
    EndIf
    For $i = 0 To UBound($aClassList) - 1
        If $aClassList[$i] = $iCurrentClass Then
            $iCurrentCount += 1
        Else
            $iCurrentClass = $aClassList[$i]
            $iCurrentCount = 1
        EndIf
        $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]")
        $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}")
        $aPos = ControlGetPos($hCallersWindow, "", $hControl)
        $sControlID = _WinAPI_GetDlgCtrlID($hControl)
        $bIsVisible = ControlCommand($hCallersWindow, "", $hControl, "IsVisible")
        If $bOnlyVisible And Not $bIsVisible Then
            $iTotalCounter += 1
            ContinueLoop
        EndIf
        If StringLen($sStringIncludes) > 0 Then
            If Not StringInStr($text, $sStringIncludes) Then
                $iTotalCounter += 1
                ContinueLoop
            EndIf
        EndIf
        If IsArray($aPos) Then
            ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF)
        Else
            ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF)
        EndIf
        If Not WinExists($hCallersWindow) Then ExitLoop
        $iTotalCounter += 1
    Next
EndFunc   ;==>GetAllWindowsControls
 
This is the error being reported when performing syntaxcheck prod
>"C:\Program Files (x86)\AutoIt3\SciTE\..\au3check.exe" -q "C:\Srikanth\Trials\AutoIT\Get_All_Controls.au3"
"C:\Trials\AutoIT\Get_All_Controls.au3"(10,1) : error: syntax error (illegal character)
 
^
"C:\Trials\AutoIT\Get_All_Controls.au3"(10,1) : error: Statement cannot be just an expression.
 
^
C:\Trials\AutoIT\Get_All_Controls.au3 - 2 error(s), 0 warning(s)
>Exit code: 2    Time: 0.6297

 
Posted

I did F5 on SciTE editor and it reports the below error

C:\Srikanth\Trials\AutoIT\Get_All_Controls.au3 (10) : ==> Unable to parse line.:
    If Not IsHWnd($hCallersWindow) Then
^ ERROR

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
  • Recently Browsing   0 members

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