Sign in to follow this  
Followers 0
HotSauce

get ID or ClassNN for a control/button?

7 posts in this topic

Given the text of a button (either all or partial), is it possible to get the ID or ClassNN for that button? (e.g. 'Button1')

Share this post


Link to post
Share on other sites



Exact text?... Partial Text?

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I could only get this to work with an exact match.

Run("calc.exe")
WinWaitActive("Calculator")

;Enter 9999 into calculator
For $x = 0 to 3
    ControlClick("Calculator", "", "[CLASS:Button; TEXT:9;]")
Next

;Click backspace button 4 times
For $x = 0 to 3
    ControlClick("Calculator", "", "[CLASS:Button; TEXT:Backspace;]")
Next

EDIT: Need like CtrlMatchMode or something.

Edited by weaponx

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What I really need to do is send a ControlClick command to a button, but some of the text on that button changes in my tests. I've tried this:

ControlClick("title", "text", "[CLASS:Button; TEXT:&FOO]")

Unfortunately that requires the exact text on the button ("FOO" in this case).

Is there any way to iterate through the controls on a window?

Edited by HotSauce

Share this post


Link to post
Share on other sites

It looks like I can use ControlGetText on buttons. The problem is when I iterate through the ButtonNN controls starting from NN = 1, I'm getting buttons from all of the app's dialog windows (previous and next).

Share this post


Link to post
Share on other sites

Seems like a hack, but my problem is solved. This searches for visible buttons that contain the text I'm looking for, and it unchecks that (checkbox) button if it is checked.

$title = "Marshmallow Fluff Installer"
$text = ""
$checktext = "I understand by leaving this box checked I will be allowing the Marshmallow Fluff Overlord to "
$i = 1
While Not @error = 1 
    If ControlCommand($title, $text, "Button" & $i, "IsVisible", "") Then
        $text = ControlGetText($title, $text, "Button" & $i)
        If StringInStr($text, $checktext) Then
            If ControlCommand($title, $text, "Button" & $i, "IsChecked", "") Then
                ControlFocus($title, $text, "Button" & $i)
                ControlClick($title, $text, "Button" & $i)
            EndIf
            MsgBox(64, "Unchecked", $text)
        EndIf
    EndIf
    $i += 1
WEnd

Please let me know if there is an easier/better way!

Share this post


Link to post
Share on other sites

Doesn't seem like much of hack to me. I was thinking along the same lines. I'm kind of surprised there isn't a builtin function like winlist to get an array of the controls. My guess is that it's because it would be too complex of an array.

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