Jump to content

Frustrated with ControlID's - can you help?


Recommended Posts

:"> I am fairly new at Autoit, so please forgive me.

I would like to send a MouseClick comand to a button that does not have a corresponding shortcut. I am using the following script to assertain the location of the button (as it will move for each user) and then to click on it. The probelm is that each time the program that contains the button opens it changes the ControlID and ClassNameNN :( .

$pos = ControlGetPos("Glossary", "", 3671004)
$x = Number($pos[0]+ 40)
$y = Number($pos[1]+ 30)
MouseClick("left", $x, $y, 650, 1)

I am willing to try anything at this stage. If you could help it would be great.

Edited by Katy
Link to comment
Share on other sites

Does the text change on the control ?

For your code, look at Opt(MouseCoordMode, 0) ; or 2 for client area. This is mouse for window setting, rather then mouse for whole screen. If you have not already.

:(

Edited by MHz
Link to comment
Share on other sites

Does the text change on the control ?

For your code, look at Opt(MouseCoordMode, 0) ; or 2 for client area. This is mouse for window setting, rather then mouse for whole screen. If you have not already.

:(

<{POST_SNAPBACK}>

Thanks, I have tried the MouseCoordMode Option and it seems to be working a little better. Does this have an effect on the ControlID? Why does the ControlID and ClassNameNN change?

The button is an Edit button but there is no Text specified in the AutoIt Window Info. Can I use the word 'Edit' anyway?

Link to comment
Share on other sites

:"> I am fairly new at Autoit, so please forgive me.

I would like to send a MouseClick comand to a button that does not have a corresponding shortcut. I am using the following script to assertain the location of the button (as it will move for each user) and then to click on it. The probelm is that each time the program that contains the button opens it changes the ControlID and ClassNameNN  :( .

$pos = ControlGetPos("Glossary", "", 3671004)

$x = Number($pos[0]+ 40)

$y = Number($pos[1]+ 30)

MouseClick("left", $x, $y, 650, 1)

I am willing to try anything at this stage. If you could help it would be great.

<{POST_SNAPBACK}>

Can you retrieve the buttons text with ControlGetText ( "title", "text", controlID ) if you have the id, if so try this (very dirty try, did not test it so dont know if this works):
$buttontext = "&Next";replace this with the buttons text
$Handle = WinGetHandle ( "Glossary" ); i prefer handles, titles do change sometimes
$ButtonClassNameNN = Get_button_classNameNN($Handle,$buttontext,Misc_funcs_number_Classlist($Handle))

$clicked = ControlClick ($Handle, $buttontext, $ButtonClassNameNN , "left")
;  :-)
If $clicked then
       msgbox(0,"INFO","Damn, am i awesome")
Else
       msgbox(0,"ERROR","@#&GRR, this is not working (Readdy for a the nutthouse)")
Endif

;gets the CalssNameNN based on a button text search (i hope)
Func Get_button_classNameNN($title,$buttontext,$numbered_classlist_array)
    Local $i
    For $i = 1 to Ubound($numbered_classlist_array)-1
        If ControlGetText ( $title, "", $numbered_classlist_array[$i] ) = $buttontext Then
            Return $numbered_classlist_array[$i]
        Next
    Next
    SetError(1)
    Return ""
Endif

;returns a numbered ClassNameNN array like Button1,Button2
Func Misc_funcs_number_Classlist($Handle)
    Local $Classlist, $ClassArray, $i, $count, $oldItem
    $Classlist = StringSplit(Misc_funcs_sort(WinGetClassList($Handle)),@CRLF,1)
    Dim $ClassArray[Ubound($Classlist)-1]
    $count = 1
    $oldItem = ""
    $ClassArray[0] = $Classlist[0]-1
    For $i = 1 To Ubound($Classlist)-2
        If $Classlist[$i] = $oldItem Then
            $count = $count + 1
        Else
            $count = 1
        EndIf
        $ClassArray[$i] = $Classlist[$i] & $count
        $oldItem = $Classlist[$i]
        ConsoleWrite("ClassNameNN: " & $ClassArray[$i] & @LF)
    Next
    $LASTCLASSLIST = WinGetClassList($Handle)
    Return $ClassArray
EndFunc

Let me know if this works :(

Link to comment
Share on other sites

Thanks, I have tried the MouseCoordMode Option and it seems to be working a little better. Does this have an effect on the ControlID? Why does the ControlID and ClassNameNN change?

The button is an Edit button but there is no Text specified in the AutoIt Window Info. Can I use the word 'Edit' anyway?

<{POST_SNAPBACK}>

MouseCoordMode allows your mouse to work within the window.

'Edit' , yes. 4 different ways to recognize a control. Text is one. Autoit info tool will display this.

Link to comment
Share on other sites

Can you retrieve the buttons text with ControlGetText ( "title", "text", controlID ) if you have the id, if so try this (very dirty try, did not test it so dont know if this works):CODE

$buttontext = "&Next";replace this with the buttons text

$Handle = WinGetHandle ( "Glossary" ); i prefer handles, titles do change sometimes

$ButtonClassNameNN = Get_button_classNameNN($Handle,$buttontext,Misc_funcs_number_Classlist($Handle))

$clicked = ControlClick ($Handle, $buttontext, $ButtonClassNameNN , "left")

;  :-)

If $clicked then

      msgbox(0,"INFO","Damn, am i awesome")

Else

      msgbox(0,"ERROR","@#&GRR, this is not working (Readdy for a the nutthouse)")

Endif

;gets the CalssNameNN based on a button text search (i hope)

Func Get_button_classNameNN($title,$buttontext,$numbered_classlist_array)

    Local $i

    For $i = 1 to Ubound($numbered_classlist_array)-1

        If ControlGetText ( $title, "", $numbered_classlist_array[$i]) = $buttontext Then

            Return $numbered_classlist_array[$i]

        Next

    Next

    SetError(1)

    Return ""

Endif

***FUNCTIONS - See Original Post***

Let me know if this works

:( WOW...This seems seriously complicated :-) May take me a while to get back to you on this one.

Thanks.

Edited by Katy
Link to comment
Share on other sites

  • 1 year later...

I am having the same issue with a .NET app.

I have verified that ControlIDs are not static in .NET 1.1 or .NET 2.0.

I'll try the large block of code provided above and see if i can make it do anything..

Quasar

Turns out the ClassName does not seem to change on .NET controls, so i was able to use it instead of the ControlID and it seems to work great.

Quasar

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...