Jump to content

Wanted: New way of identifying windows and controls


Jon
 Share

Recommended Posts

  • Administrators

As part of the control/window code rewrite I want to improve how Autoit references windows and controls.

Once we identify a window we can grab it's HWND handle - which is great. But finding the correct window/control in the first place can be tricky.

Currently we have these ways of identifying windows:

- By title/text (simple text and also with "RegExp=")

- By classname ("classname=")

And for controls:

- By simple text caption

- By a combination of classname and instance (referred to in AutoIt as ClassNameNN)

- By control ID (used to be the best method, but less useful now that .NET framework breaks it)

This works pretty well, but it has some flaws:

- Inconsistant between identifying controls and windows, especially those with a classname. After all a control IS a window so this is odd.

- If you open 3 identical windows there is no way to easily identify the 1st, 2nd, 3rd. You always get the first. (WinList wrangling required).

I want to implement a single identification mechanism for windows and controls. But I don't want to break existing stuff, and I'm NOT keen on adding another Opt() function to switch. So I need some ideas. I'm thinking something like this:

[title="...", regexptitle="...", class="...", instance="..."]

So, to reference the 3rd new notepad window you could do

[title="Untitled", instance="3"]

or

[class="Notepad", instance="3"]

This would be the same for controls. A previous ClassNameNN of "Button123" would be:

[class="Button", instance="123"]

This would be used as the "Title" parameter of a Win...() function or as the "ClassNameNN" parameter of a Control...() function. Do you think it needs to be made more obvious (and less likely to be a real window name) like:

au3info[title="", class=""]

or

[[title=""]]

or

[[[title=""]]]

Or is it too unwieldy and it's fairly unlikely that we would get a clash anyway? (Don't want to rely on the WinTitleMatchMode thing)

Link to comment
Share on other sites

Or is it too unwieldy and it's fairly unlikely that we would get a clash anyway? (Don't want to rely on the WinTitleMatchMode thing)

I think this your new way should work only with WinTitleMatchMode = 4 (or maybe 5?)

Most of users will be using Mode 1 anyway and more experienced users have no problem to use Mode 4 now

so it will be in consistence with previous logic in the future.

Edited by Zedna
Link to comment
Share on other sites

  • Administrators

It doesn't make sense for windows to only use it when in matchmode 4 and controls to use it all the time though (again, inconsistancy). It should be fairly easy to check that the title begins and ends with [ ] and that it contains correct formatting. The only risk is if you need to identify a window with the exact same title, but then you could do that with [title="really unlikely title"] so not much a problem now that I think about it.

Link to comment
Share on other sites

It doesn't make sense for windows to only use it when in matchmode 4 and controls to use it all the time though (again, inconsistancy). It should be fairly easy to check that the title begins and ends with [ ] and that it contains correct formatting. The only risk is if you need to identify a window with the exact same title, but then you could do that with [title="really unlikely title"] so not much a problem now that I think about it.

Yes you are right Jon. Your arguments are clear to me now and I agree.

By the way: Thanks for neverending development of AutoIt guys :whistle:

Link to comment
Share on other sites

  • Administrators

[title="...", regexptitle="...", class="...", instance="..."]

Hmm, I forgot that the quotes would cause issues - don't want to make it annoying by having to do double quotes or swap between single and double ones.

WinWait("[class=""myclass""]") or WinWait("[class='myclass']") are both a little fiddly and a quote accident waiting to happen.

Maybe just:

WinWait("[title:My Long Title; class:myclass; instance:3]")

Link to comment
Share on other sites

  • Administrators

Maybe just:

WinWait("[title:My Long Title; class:myclass; instance:3]")

Got this working quite well locally on windows. Need to port it to the controls too and then some testing needed :whistle:
Link to comment
Share on other sites

  • Administrators

Uploaded test versions of just AutoIt3.exe and Au3Info.exe to http://www.autoitscript.com/autoit3/files/beta/autoit/

Both windows and controls accept descriptions in the form "[PROPERTY:value; PROPERTY2:value2]"

Windows have the properties:

class

title

instance

last

active

regexptitle

Controls have:

class

instance

classnn (legacy testing)

id

text

Example of Notepad text:

ControlSetText("Untitled -", "", "[class:Edit]", "New Text Here" )
 ƒo݊÷ ØZ+¶¶ÙèµêZw§vŒ-ŠÙ^v«¨µIíŠÙ^v«¨¶)í…æN­×«jëhŠ×6
ControlSetText("[title:Untitled; instance:2]", "", "[class:Edit]", "New Text Here" )

If you want to include ; : [ ] in the actual value of a property then double it up

"[title:This is single colon::did you see it?]"

It seems fairly longwinded but it's fine in conjunction with ControlGetHandle and WinGetHandle. And existing simple titles are still there - this is just when you need to more accurately specifiy a particular window/control.

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