Sign in to follow this  
Followers 0
malczu

AutoIt in C# INSTANCEID and X / Y / W / H

3 posts in this topic

Hi

According to documentation we can use X / Y / W / H coordinates to select control. Unfortunately this doesn't work for me, and I have found it to be only option to select control due to changing INSTANCEID every time I re run application. Could you please advise?

Example code in Auto It script

ControlCommand("Win","","[CLASS:TComboBox; X:567; Y:421]", "GetCurrentSelection")

I have tried without CLASS as well, and by adding W and H as well. When I use class and instanceid it works fine.

Thanks

Share this post


Link to post
Share on other sites



I made a function to list all controls (and informations of controls) for a given Window.

Maybe you can use it to retrieve the InstanceID from X / Y / W / H ?

#Include <Array.au3> ; Only for the example (_ArrayDisplay)


; Example 1 : list controls from Calculator ####################################################################
Run("calc.exe")
WinWait("[CLASS:CalcFrame]")

Local $list = _getControlsList(WinGetHandle("[CLASS:CalcFrame]") )
If $list = 0 Then Exit MsgBox(0, "Controls list" , "No control found for " & WinGetTitle("[CLASS:CalcFrame]") )

_ArrayDisplay($list, "Controls list", Default, 0, "|", "ClassnameNN|Advanced Mode|Handle|Text|ID|Advanced mode (ID)|Position from Window)|Size|Position from screen")

; ##############################################################################################################




Func _getControlsList($hWND)
    Local $sClassList = WinGetClassList($hWND, "")
    Local $aClasses = StringRegExp($sClassList, "(\N+)(?:\R|$)", 3)
    Local $aList[1] = [0], $iIndex = 0, $aControlPos, $aScreenPos
   
    Local $aResult[ UBound($aClasses) ] [9]
   
    For $i = 0 To UBound($aClasses) - 1
        If IsDeclared("CLASS_" & $aClasses[$i]) Then
            Assign("CLASS_" & $aClasses[$i], Eval("CLASS_" & $aClasses[$i]) + 1)
        Else
            Assign("CLASS_" & $aClasses[$i], 1)
           
            Redim $aList[ UBound($aList) + 1]
            $aList[UBound($aList) - 1] = $aClasses[$i]
            $aList[0] += 1
        EndIf
    Next
   
   
    For $i = 1 To $aList[0]
        For $j = 1 To Eval("CLASS_" & $aList[$i])
            $aResult[$iIndex][0] = $aList[$i] & $j                                                 ; ClassnameNN
            $aResult[$iIndex][1] = "[CLASS:" & $aList[$i] & "; INSTANCE:" & $j& "]"                ; Advanced mode
            $aResult[$iIndex][2] = ControlGetHandle($hWND, "", $aResult[$iIndex][1])               ; Handle
            $aResult[$iIndex][3] = ControlGetText($hWND, "", $aResult[$iIndex][2])                 ; Text
            $aResult[$iIndex][4] = _GetCtrlID($aResult[$iIndex][2])                                ; ID
            $aResult[$iIndex][5] = "[CLASS:" & $aList[$i] & "; ID:" & $aResult[$iIndex][4] & "]"   ; Advanced mode (ID)
           
            $aControlPos = ControlGetPos($hWND, "", $aResult[$iIndex][2])
            If IsArray($aControlPos) Then
                $aResult[$iIndex][6] = "X=" & $aControlPos[0] & " ; Y=" & $aControlPos[1]          ; Position X,Y (in the Window)
                $aResult[$iIndex][7] = "W=" & $aControlPos[2] & " ; H=" & $aControlPos[3]          ; Width and Height
            EndIf
           
            $aScreenPos = WinGetpos($aResult[$iIndex][2])
            If IsArray($aScreenPos) Then
                $aResult[$iIndex][8] = "X=" & $aScreenPos[0] & " ;  Y=" & $aScreenPos[1]           ; Position X,Y (in the screen)
            EndIf
           
            $iIndex += 1
        Next
    Next
   
    Return $aResult
EndFunc






Func _GetCtrlID($hWnd) ; From WinAPI.au3
    Local $aResult = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hWnd)
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetDlgCtrlID

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