Jump to content

identifying a WindowsForms control which changes CLASS and ID each run


Chris
 Share

Recommended Posts

Hi,

Are there any tricks I can use to identify a control (for use with the ControlXXX commands) when the

CLASS and ID seem to be changing each time the application is run.

It's a .NET app and I think the form is dynamically adding the controls...

I was using an id like this:

"[CLASS:WindowsForms10.BUTTON.app4; INSTANCE:1]"

but when I run the program as different users, the app4 part changes (I've seen app4 and app5).

I changed to using ID (eg "[iD:65432]") but the ID of the button changes every time the application runs (although I read in the forum or faq that the ID is supposedly the most reliable way of identifying a control).

The button I want to activate has an image but no text, however fortunately it's our own application so I've worked around it by adding a tiny button (hidden behind the original one) which performs the same action and has text which I can use (So now I'm using "[TEXT:Blah]") to find the hidden button and I'm sending a message to that instead.

Still I was wondering if anyone knows if there is a better way of doing it or of getting the .NET forms to generate a consistent id that is visible to AutoIt (I tried setting AccessibleName and properties like that but couldnt find them in the autoit info).

cheers

Link to comment
Share on other sites

I've tried automating a .NET application but its control ID, classname or instance never changed. So I had to go with what you said in the first post, and hope I am doing it correctly.

You can use a REGEXPCLASS to find the correct control you are looking for. It's useful to find a control by classname using a regular expression.

$hWnd = WinGetHandle("[active]")
$ControlClass = "[REGEXPCLASS:WindowsForms10\.BUTTON(.*)?; INSTANCE:1]"
$ChWnd = ControlGetHandle($hWnd, "", $ControlClass)

For more information, please look at:

http://www.autoitscript.com/autoit3/docs/f...tringRegExp.htm

http://www.autoitscript.com/autoit3/pcrepattern.html

http://www.autoitscript.com/autoit3/docs/t...gexp/regexp.htm

http://www.codeproject.com/KB/dotnet/regextutorial.aspx

Link to comment
Share on other sites

If the developer gave the control a name at design-time, you can appropriate it via a WM_GETCONTROLNAME message. Look here for an example I ported on how to do this. Hope it helps; let me know if it doesn't.

Zach...

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