Jump to content

How to test the existence of a Control ID ?


Recommended Posts

Hello,

I'm trying to use AutoIt, in order to automate the setup of an application.

By using "Active Windows Info", I'd see that during the different stage of the setup, the main title of the windows doesn't change (so, i could'nt use WinWaitActive like i used to do).

I'd decided to test the Control ID of some controls (ie "The InstallShield® Wizard will install ..." -> ControlID#:710), i'd tried by using GUICtrlRead & GUICtrlGetState but i couldn't get it work.

I want to test the existence of a control ID, but i dont know which function i'm supposed to use. :whistle:

Can somebody help me ? Thanks

Link to comment
Share on other sites

Hello,

I'm trying to use AutoIt, in order to automate the setup of an application.

By using "Active Windows Info", I'd see that during the different stage of the setup, the main title of the windows doesn't change (so, i could'nt use WinWaitActive like i used to do).

I'd decided to test the Control ID of some controls (ie "The InstallShield® Wizard will install ..." -> ControlID#:710), i'd tried by using GUICtrlRead & GUICtrlGetState but i couldn't get it work.

I want to test the existence of a control ID, but i dont know which function i'm supposed to use. :whistle:

Can somebody help me ? Thanks

Maybe using ControlGetHandle, ControlGetText, ControlGetPos or something, repeatedly until @error = 0 (or return value is not ""). Since these functions should fail if the control is not accessible (for instance because it isn't there yet :P) maybe this suits your purpose?

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Look up WinGetClassList(). This is an example which I think would work as a concept, but I am unable to test it right now.

Func _ControlExists($WName, $CCName)
local $WControls=stringsplit(WinGetClassList($WName),@LF)
for $ICount = 1 to $WControls[0]
if $WControls[$ICount]=$CCName then return 1
next
return 0
EndFunc

This Function should return 1 if the control is found, or 0 if it is not. Not that rather then checking for Control ID it is checking for ClassNameNN, which means that you will either need to pass that as the second parameter of the function, or change the function accordingly.

Edited by improbability_paradox
Link to comment
Share on other sites

  • Moderators

I've always used something like SadBunny has shown.

If ControlGetHandle('Window', 'Control Text', 'Control ID') Then 
    MsgBox(64, 'Info', 'Control Exists')
Else
    MsgBox(16, 'Error', 'Control Does Not Exists')
EndIf

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

  • Moderators

Ha... see what I get for writing on the fly...

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

  • Moderators

Heheh... I'm sure Smoke will never ever write anything on the fly again... :D

Control text...shouldn't that be window text ? :lmao:

Um... No... It's Control text :whistle: (Might want to check that one out for yourself :P )

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

In fact I did test that. If you're right then I don't understand the use of the 2nd parameter.

The following code is working with the buttons in the Run-dialog. OK is the text of the...well, OK-button,

while Button4 is the ID of the Browse-button. What button is clicked ? The Browse-button and not the

OK-button. Why ? Because OK is a part of the window-text and Button4 is the ID for the Browse-button.

ControlClick("Kjør", "OK", "Button4")

Edit : If I'm wrong on this one I'll take that as a hint and head straight for bed :whistle:

Edited by Helge
Link to comment
Share on other sites

  • Moderators

In fact I did test that. If you're right then I don't understand the use of the 2nd parameter.

The following code is working with the buttons in the Run-dialog. OK is the text of the...well, OK-button,

while Button4 is the ID of the Browse-button. What button is clicked ? The Browse-button and not the

OK-button. Why ? Because OK is a part of the window-text and Button4 is the ID for the Browse-button.

ControlClick("Kjør", "OK", "Button4")

Edit : If I'm wrong on this one I'll take that as a hint and head straight for bed :whistle:

I've always used it this way personally,

Control ID = 1

Text = '&OK'

ClassNameNN = 'Something'

ControlGetHandle($Win, '&OK', 'Something')

I think very early on in my starting with AutoIt I found it didn't work with just 'Win Text', so I used the text that AutoInfo provided, and it always worked fine.

Maybe you are right and I am wrong... you're example would prove me to be wrong of course, but I would have bet a bundle I wasn't.

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

Maybe you are right and I am wrong... you're example would prove me to be wrong of course, but I would have bet a bundle I wasn't.

I should probably keep my mouth shut as a newcomer here, ESPECIALLY when pointing to the help of a function I have not used myself and even more when speaking to one of the most esteemed and active posters here... I know my place but I can't help it :whistle:

Anyway, look at the GontrolGetHandle help text:

ControlGetHandle ( "title", "text", controlID)

Parameters

title The title of the window to access.

text The text of the window to access.

controlID The control to interact with. See Controls.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Afterthought: to soothe the harshness of my near-blasphemic post just there, I will tell you that my first thought after looking this up in the help file and comparing it to Smoke's post was: "Gee, the help file must be wrong". To go short: after being on this forum for a couple of months, I learned to trust Smoke :-)

(Btw, the next thing I thought was that since I had not tested let alone used this function was that I had to be not getting something due to newbiness...)

Anyway, I'll go to bed myself now :whistle:

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

  • Moderators

Afterthought: to soothe the harshness of my near-blasphemic post just there, I will tell you that my first thought after looking this up in the help file and comparing it to Smoke's post was: "Gee, the help file must be wrong". To go short: after being on this forum for a couple of months, I learned to trust Smoke :-)

(Btw, the next thing I thought was that since I had not tested let alone used this function was that I had to be not getting something due to newbiness...)

Anyway, I'll go to bed myself now :P

No worries, If I'm right 20% of the time, that's good for me :whistle:

Anyway, you have to remember that the last time I probably read that thing was 2 years ago, that may or may not have been there.

But to open everyones mind a bit... If you use the Control "Text" << wouldn't that also be a part of the "Win" text?

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

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