Sign in to follow this  
Followers 0
Aceguy

Func creating

4 posts in this topic

hi im trying to create a func that clicks a control if its there.... ie. a button... if not there, wait.?

something like

func _cwc($title,$id,$txt)
    do
        
    $rt_txt=ControlGetText($title,"",$id)
    sleep(250)
until $rt_txt=$txt
sleep(100)
ControlClick($title,$txt,$id,"left",1)
sleep(100)
EndFunc

anyone know of a betterway. or is this ok.?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Func _ControlWait($h_wnd, $s_text, $v_control, $i_timeout = 0)
    Local $h_control = 0, $i_timer = TimerInit()
    While Not $h_control
        $h_control = ControlGetHandle($h_wnd, $s_text, $v_control)
        If $i_timeout And TimerDiff($i_timer) / 1000 >= $i_timeout Then
            Return SetError(1, 0, 0)
        EndIf
        Sleep(250)
    WEnd
    Return $h_control
EndFunc

Edit:

Just in case you're confused on how to use it:

Global $h_c = _ControlWait("My Window Handle/Title", "Text If Any", "ControlID or Other Identifier")
ControlClick("My Window Handle/Title", "Text If Any", $h_c)

Edit2:

Looking at your code, I can see you're probably not familiar with how to use the special description parameters.

If you're waiting for a control, have no idea what its ID or ClassNameNN is going to be, and the only thing you do know is it's a button, and what text will show.

You may want to try something like:

Global = $s_text_to_wait_for = "ButtonIsHereNow"
Global $h_c = _ControlWait("My Window Handle/Title", "Text If Any", "[CLASS:Button; TEXT:" & $s_text_to_wait_for & "]")
ControlClick("My Window Handle/Title", "Text If Any", $h_c)

You can find these special features for controls in the help file:

Content Tab -> Using AutoIt -> Controls

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

WOW fast, and superb, ty

NP, be sure to see the last edit with special descriptors.

[center]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.[/center]

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