Jump to content

Can't distinguish buttons


bo8ster
 Share

Recommended Posts

Hi all

I have got stuck on a problem distinguishing between two different buttons on two different subtabs (within the same program). Using the Auto Window info gives me the two buttons in question.

Add Physician button

>>>> Window <<<<

Title: Eye Cubed - [iD: 00001020, Name: Guild, Harry, D.O.B: 7/08/2008]

Class: TFormBase.UnicodeClass

Position: -4, -4

Size: 1928, 1178

Style: 0x17C70000

ExStyle: 0x00050100

Handle: 0x013A0246

>>>> Control <<<<

Class: TTntBitBtn.UnicodeClass

Instance: 3

ClassnameNN: TTntBitBtn.UnicodeClass3

Advanced (Class): [CLASS:TTntBitBtn.UnicodeClass; INSTANCE:3]

ID: 30212798

Text: Add Physician

Position: 665, 527

Size: 170, 40

ControlClick Coords: 124, 12

Style: 0x5401000B

ExStyle: 0x00000000

Handle: 0x01CD02BE

Reset Button

>>>> Window <<<<

Title: Eye Cubed - [iD: 00001020, Name: Guild, Harry, D.O.B: 7/08/2008]

Class: TFormBase.UnicodeClass

Position: -4, -4

Size: 1928, 1178

Style: 0x17C70000

ExStyle: 0x00050100

Handle: 0x013A0246

>>>> Control <<<<

Class: TTntBitBtn.UnicodeClass

Instance: 3

ClassnameNN: TTntBitBtn.UnicodeClass3

Advanced (Class): [CLASS:TTntBitBtn.UnicodeClass; INSTANCE:3]

ID: 20448090

Text: Reset

Position: 150, 1065

Size: 140, 40

ControlClick Coords: 58, 17

Style: 0x5401000B

ExStyle: 0x00000000

Handle: 0x0138035A

I want to use ControlGetHandle to get a handle to the buttons but the ClassnameNN and Instance for both buttons are the same, I can't tell them apart. I use the following code to get the rest button.

Func getResetButtonHandle()

Local $handle = ""

$handle = ControlGetHandle($appHandle, "", "TTntBitBtn.UnicodeClass3")

Return $handle

EndFunc

Trying to tell the difference between the two, I used the below code but it did not work, it gets the rest button.

Func getAddPhysicianButtonHandle()

Local $handle = ""

$handle = ControlGetHandle($appHandle, "", "[CLASSNN:TTntBitBtn.UnicodeClass3; TEXT:Add Physician]")

If $handle == "" Or ControlGetText($handle, "", "") <> "Add Physician" Then

MsgBox(0, "", $handle)

MsgBox(0, "", ControlGetText($handle, "", ""))

MsgBox(0, "Handle Error", "Add Physician Button handle not obtained")

EndIf

Return $handle

EndFunc

any ideas?

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Use the text of the control to help identify it:

Text: Reset

Text: Add Physician

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Like this:

ControlGetHandle($appHandle, "", "[CLASS:TTntBitBtn.UnicodeClass; INSTANCE:3; TEXT:Reset]")

:)

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Thanks for the reply

Now using

Global Const $pPhysicianHandle = getPPhysicianHandle()
Global Const $resetButton = getResetButtonHandle()

Func getAddPhysicianButtonHandle()
    Local $handle = ""
    $handle = ControlGetHandle($appHandle, "", "[CLASS:TTntBitBtn.UnicodeClass; INSTANCE:3; TEXT:Add Physician]")
    If $handle == "" Or ControlGetText($handle, "", "") <> "Add Physician" Then
        MsgBox(0, "", $handle)
        MsgBox(0, "", ControlGetText($handle, "", ""))
        MsgBox(0, "Handle Error", "Add Physician Button handle not obtained")
    EndIf
    Return $handle
EndFunc

Func getResetButtonHandle()
    Local $handle = ""
    $handle = ControlGetHandle($appHandle, "", "[CLASS:TTntBitBtn.UnicodeClass; INSTANCE:3; TEXT:Reset]")
;~  $handle = ControlGetHandle($appHandle, "", "TTntBitBtn.UnicodeClass3")  
    If $handle == "" Or ControlGetText($handle, "", "") <> "Reset" Then
        MsgBox(0, "Handle Error", "Reset Button handle not obtained")       
    EndIf   
    Return $handle
EndFunc

I am not getting the reset button. Not an expert, why are the instances the same when they are different buttons?

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

you said the buttons where on different tabs. If you reverse things, bring up the tab with the reset does the problem reverse itself?

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I assume you mean instantiation order. I know it is important but I don’t have a choice, the reset button is shown as the program loads up.

I have this issue with several other buttons, this is just one example.

Using the above code, no buttons are found. Using the commented line in the reset function always finds the reset button.

I checked in the dev IDE and they are two difference instances, I have seen a button re-label.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Is there a way to specify a button within a tab in the same way that a that I have specified a button within the program (appHandle)?

Example, tab one, instance 3, tab three, instance 3.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

hmm I don't think you can specify tabs.

You could try the ID's, but I'm not sure if they change or are static I've never used them before.

They are most likely static though

$handle = ControlGetHandle($appHandle, "", "[ID:30212798]");Reset Button

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Just tested that and as I thought, the Control IDs and Handles are dynamic.

Two control IDs and Handles when running the program twice

39125750

0x013C0344

20579082

0x013A030A

Thanks for the suggestion though.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

hmm stubborn window lol

Not sure what else to do, did you copy the text values right out the the info tool and paste them into the script or type them? I've seen them having spaces before or after sometimes.

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

stubborn indeed.

No spaces - i'm a little stumped. I guess I will have to do some doco until it gets sorted.

Thanks for ur help mate.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Managed to get it sorted.

Here is code for two buttons that have the same class and instance number

Global Const $resetButton = getResetButtonHandle()
Global Const $addPhysicianButton = getAddPhysicianButtonHandle()

Func getResetButtonHandle()
    Local $handle = ""
    $handle = ControlGetHandle($appHandle, "", "[CLASS:TTntBitBtn.UnicodeClass; TEXT:Reset]")
    If $handle == "" Or ControlGetText($handle, "", "") <> "Reset" Then
        MsgBox(0, "Handle Error", "Reset Button handle not obtained")       
    EndIf   
    Return $handle
EndFunc

Func getAddPhysicianButtonHandle()
    Local $handle = "" 
    $handle = ControlGetHandle($appHandle, "", "[CLASS:TTntBitBtn.UnicodeClass; TEXT:Add Physician;]")
    If $handle == "" Or ControlGetText($handle, "", "") <> "Add Physician" Then
        MsgBox(0, "", $handle)
        MsgBox(0, "", ControlGetText($handle, "", ""))
        MsgBox(0, "Handle Error", "Add Physician Button handle not obtained")
    EndIf
    Return $handle
EndFunc

Changes to the this and the above code is, no mention of Instance number (had to move away from ClassNN) - not really sure why but less info is better here;

The addition of the semi-colon ';' after the given TEXT arg - not sure if it is required and it is not shown in the AutoIt help but it works now :)

Hope it helps anyone else that has the same issue.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

What did u do, just get rid of the instance value?

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

  • Moderators

Using ControlGetText() in the manner you've shown is going to cause issues in later programs.

You could use _CtrlGetByPos() possibly to get the correct button.

_CtrlGetByPos() : http://www.autoitscript.com/forum/index.ph...c=30717&hl=

Or Maybe:

_WinGetCtrlInfo() : http://www.autoitscript.com/forum/index.ph...c=32781&hl=

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.

Link to comment
Share on other sites

That and the semi-colon but I think that makes no difference.

The help file says for controls "INSTANCE - The 1-based instance when all given properties match" and that ClassNN is old. So I thought I should move to CLASS and specify other properties first, the use instance only if I had to.

I think it searches the app for a Instance of a Class with the given Text and Instance can be used to tell the difference when more then one result is found.

I am going to hit the same issue with two List Views "TTntListView.UnicodeClass1" but i'll cross that bridge when I come to it.

Either way, from this I recommend taking the ordering from the help file as order of importance, thus look at instance last.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Using ControlGetText() in the manner you've shown is going to cause issues in later programs.

You could use _CtrlGetByPos() possibly to get the correct button.

_CtrlGetByPos() : http://www.autoitscript.com/forum/index.ph...c=30717&hl=

Or Maybe:

_WinGetCtrlInfo() : http://www.autoitscript.com/forum/index.ph...c=32781&hl=

Thanks SmOke_N for the info.

they are some serious functions - i'm still learning. I'll try _CtrlGetByPos() for the two ControlListViews of the same Instance number I have. I can get one with

Local $handle = ControlGetHandle($appHandle, "", "TTntListView.UnicodeClass1")
but have my doubts about the second on another tab which looks to be the same - same ClassNN and no Text but the Position is different.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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