Jump to content

WinGetControlFromClientPosition


LarryDalooza
 Share

Recommended Posts

I had a need for this... so I whipped it up wit quickness... Thought I'd post it before I lose or delete it...

MsgBox(4096,"","This clicks ""Cancel"" on my Run dialog")

; Invoke Run Dialog
Send("#r")
WinWait("Run")

; Wait 3 sec and tell you what I am about to do
ToolTip("CLICKING RUN DIALOG CANCEL BUTTON")
Sleep(3000)

; WinGetControlFromClientPosition( <Title>, <Text>, <Left of Control>, <Right>, <Width>, <Height> )
; position info comes from Window Info Tool set to Options/Coord Mode/Client
; click the Control tab and use Position for left,right and Size for width,height
$hwnd = WinGetControlFromClientPosition("Run","",174,114,75,23)
ControlClick("","",$hwnd)

Func WinGetControlFromClientPosition($title,$text,$left,$right,$width,$height)
    Local $control,$controls,$ctrl,$i,$pos
    Local $opt = Opt("PixelCoordMode",2)
    
    $controls = @LF & WinGetClassList($title,$text)
    
    While StringLen(StringReplace($controls,@LF,""))
        $control = StringLeft($controls,StringInStr($controls,@LF,0,2))
        $i = 0
        While StringInStr($controls,$control)
            $i += 1
            $ctrl = StringTrimRight(StringTrimLeft($control,1),1) & $i
            $pos = ControlGetPos($title,$text,$ctrl)
            If $pos[0] = $left And $pos[1] = $right And $pos[2] = $width And $pos[3] = $height Then
                Opt("PixelCoordMode",$opt)
                Return ControlGetHandle($title,$text,$ctrl)
            EndIf
            $controls = StringReplace($controls,$control,@LF,1)
        WEnd
    WEnd
    
    Opt("PixelCoordMode",$opt)
EndFunc

Lar.

edit: Reset PixelCoord before returning.

Edited by LarryDalooza

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Link to comment
Share on other sites

I had a need for this... so I whipped it up wit quickness... Thought I'd post it before I lose or delete it...

Need to reset the PixelCoordMode before returning.

MsgBox(4096,"","This clicks ""Cancel"" on my Run dialog")

; Invoke Run Dialog
Send("#r")
WinWait("Run")

; Wait 3 sec and tell you what I am about to do
ToolTip("CLICKING RUN DIALOG CANCEL BUTTON")
Sleep(3000)

; WinGetControlFromClientPosition( <Title>, <Text>, <Left of Control>, <Right>, <Width>, <Height> )
; position info comes from Window Info Tool set to Options/Coord Mode/Client
; click the Control tab and use Position for left,right and Size for width,height
$hwnd = WinGetControlFromClientPosition("Run","",174,114,75,23)
ControlClick("","",$hwnd)

Func WinGetControlFromClientPosition($title,$text,$left,$right,$width,$height)
    Local $control,$controls,$ctrl,$i,$pos
    Local $opt = Opt("PixelCoordMode",2)
    Local $Result = 0
    $controls = @LF & WinGetClassList($title,$text)
    
    While StringLen(StringReplace($controls,@LF,"")) 
        $control = StringLeft($controls,StringInStr($controls,@LF,0,2))
        $i = 0
        While StringInStr($controls,$control)
            $i += 1
            $ctrl = StringTrimRight(StringTrimLeft($control,1),1) & $i
            $pos = ControlGetPos($title,$text,$ctrl)
            If $pos[0] = $left And $pos[1] = $right And $pos[2] = $width And $pos[3] = $height Then
               $Result = ControlGetHandle($title,$text,$ctrl)                      
               ExitLoop 2
            EndIf
            $controls = StringReplace($controls,$control,@LF,1)
        WEnd
 
    WEnd
    
    Opt("PixelCoordMode",$opt)
       Return $Result
EndFunc[/autoit]

Lar.
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

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