Sign in to follow this  
Followers 0
FreeFry

Bug in advanced title matching(using instance) ?

14 posts in this topic

Unless I've totally missed something, this code seems to behave .. unexpectedly..

WinWait("[CLASS:Notepad; INSTANCE:1]")
WinActivate("[LAST]")
WinWaitActive("[LAST]")
Send("This is the first instance of the window")

WinWait("[CLASS:Notepad; INSTANCE:2]")
WinActivate("[LAST]")
WinWaitActive("[LAST]")
Send("This is the second instance of the window")

WinWait("[CLASS:Notepad; INSTANCE:3]")
WinActivate("[LAST]")
WinWaitActive("[LAST]")
Send("This is the third instance of the window")

Run the script, and open up a notepad window, it should fill it in correctly, then open up another notepad window(leave the previous one open), and it'll fill in the same window(even though it should be filling in the instance #2 window), and

when you open the third notepad window, you'll see that it fills the window that 'should' be instance #2.

If you then clear the text in all the notepad windows, and run the script again, it will properly fill in all the windows but what seems to be in reverse - assuming the first notepad window visible in the taskbar is the first instance,

it fills them in from right to left, not from left to right - as expected.

This is the first time I've used the instance property on windows, and I'm a little confused if this is the behavior that is to be expected.

It does this on two of my computers, both running the newest autoit version(3.3.0.0).

Would love if someone else could test this, and see if they have the same issue. :)

If this is not supposed to happen, should I file a bug ticket? (I had a look in the bug tracker, and could not find anything related to this..).

Share this post


Link to post
Share on other sites



Does "[LAST]" mean the last active window?


[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

From the helpfile:

LAST - Last window used in a previous AutoIt command

Edit:

This also happens when I use the "[CLASS:Notepad; Instance:1]" for all the other Window related functions, so it has nothing to do with "[LAST]", I only used that to make it more directly obvious what it was doing. :)

Edited by FreeFry

Share this post


Link to post
Share on other sites

FreeFry,

On my system (Vista x32 SP1), NotePad windows do not have Instance numbers according to the Au3Info tool. When I open several Notepad windows, they are essentially identical apart from the Windows handle. So I am not surprised that your script is having problems in identifying which is which using the INSTANCE property.

M23

P.S. Out of interest, where in the Helpfile did you find [LAST]?


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
:) You can see that WinWait with an instance number is greater than the previous notepad instance will wait for another notepad to be exists. Seems like a bug to me.

Share this post


Link to post
Share on other sites

FreeFry,

On my system (Vista x32 SP1), NotePad windows do not have Instance numbers according to the Au3Info tool. When I open several Notepad windows, they are essentially identical apart from the Windows handle. So I am not surprised that your script is having problems in identifying which is which using the INSTANCE property.

M23

P.S. Out of interest, where in the Helpfile did you find [LAST]?

http://www.autoitscript.com/autoit3/docs/i...owsadvanced.htm

I know the Au3Info tool does not tell you an instance number, but from as far as I know, all windows(based on their class I assume) has an instance starting from 1, also the the advanced title matching documentation states that windows has an instance as well.

:) You can see that WinWait with an instance number is greater than the previous notepad instance will wait for another notepad to be exists. Seems like a bug to me.

Ok, so you experience the same issue with it not activating the correct window(based on the instance) ?

Share this post


Link to post
Share on other sites

FreeFry,

It is [LAST] that is not able to cope with the INSTANCE property. Have a try with this:

Opt('MustDeclareVars', 1)

WinWait("[CLASS:Notepad; INSTANCE:1]")
WinActivate("[CLASS:Notepad]")
WinWaitActive("[LAST]")
Send("This is the first instance of the window")

WinWait("[CLASS:Notepad; INSTANCE:2]")
WinActivate("Untitled - Notepad") 
WinWaitActive("[LAST]")
Send("This is the second instance of the window")

WinWait("[CLASS:Notepad; INSTANCE:3]")
WinActivate("[CLASS:Notepad]; INSTANCE:3")
ConsoleWrite("Here" & @CRLF)
WinWaitActive("[LAST]")
Send("This is the third instance of the window")

It stalls at the final WinWaitActive.

I think we will have to wait for a Dev to come along and enlighten us all. :-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

FreeFry,

It is [LAST] that is not able to cope with the INSTANCE property. Have a try with this:

Opt('MustDeclareVars', 1)

WinWait("[CLASS:Notepad; INSTANCE:1]")
WinActivate("[CLASS:Notepad]")
WinWaitActive("[LAST]")
Send("This is the first instance of the window")

WinWait("[CLASS:Notepad; INSTANCE:2]")
WinActivate("Untitled - Notepad") 
WinWaitActive("[LAST]")
Send("This is the second instance of the window")

WinWait("[CLASS:Notepad; INSTANCE:3]")
WinActivate("[CLASS:Notepad]; INSTANCE:3")
ConsoleWrite("Here" & @CRLF)
WinWaitActive("[LAST]")
Send("This is the third instance of the window")

It stalls at the final WinWaitActive.

I think we will have to wait for a Dev to come along and enlighten us all. :-)

M23

WinActivate("Untitled - Notepad") <-- that activates the most newly created window, which is not what my example code is trying to prove

If you open up three notepad windows before running the script, it should probably fill in all the windows, in the 'correct' order - which from my assumption would be from left to right(as the windows occurs in the taskbar).

Still, if you run the script before opening any notepads, it should be able to correctly fill them out (instance 1 should be the first notepad window created, instance 2 should be the second, etc.), but when it gets to filling in the second instance window, it fills the first instance window, and when it gets to the third instance, it fills in the second instance window...

It seems that using instance to target a specific window is not reliable(unless this is indeed a bug).

I found this odd behavior while I was going to write an example to the OP in this thread, as the process he wants to automate creates 3 windows named the same way, so I thought, if it creates them in the same order each time, he could use the instance number to target the correct window. But then it seems that instances are ... not reliable, as 'proven' in my example.

Maybe the instance number is something the operating system gives the window based on something, which makes it hard to use it to identify a specific window created in a specific order...

I would really love to hear from a developer, if this is to be expected. :)

Edit:

This code makes it even more confusing:

Opt("WinTitleMatchMode", 4)

WinWait("[CLASS:Notepad; INSTANCE:1]")
ConsoleWrite("Activated first: " & WinActivate("[CLASS:Notepad; INSTANCE:1]") & @LF)
WinWaitActive("[CLASS:Notepad; INSTANCE:1]")
Send("This is the first instance of the window")

WinWait("[CLASS:Notepad; INSTANCE:2]")
ConsoleWrite("Activated second: " & WinActivate("[CLASS:Notepad; INSTANCE:2]") & @LF)
WinWaitActive("[CLASS:Notepad; INSTANCE:2]")
Send("This is the second instance of the window")

WinWait("[CLASS:Notepad; INSTANCE:3]")
ConsoleWrite("Activated third: " & WinActivate("[CLASS:Notepad; INSTANCE:3]") & @LF)
WinWaitActive("[CLASS:Notepad; INSTANCE:3]")
Send("This is the third instance of the window")

If the script is ran before any notepad windows are opened, it activates the second window when it is opened(but it's the first instance that gets activated :s), but it stays at the WinWaitActive, even though it just activated it fine.. I'm very confused atm. :|

Edited by FreeFry

Share this post


Link to post
Share on other sites

Bump.

Share this post


Link to post
Share on other sites

This is a statement that will never be true:

WinWaitActive("[CLASS:Notepad; INSTANCE:2]")

because the active window is always: INSTANCE:1

try this:

WinWait("[CLASS:Notepad; INSTANCE:1]")
ConsoleWrite("Activated first: " & WinActivate("[CLASS:Notepad; INSTANCE:1]") & @LF)
WinWaitActive("[CLASS:Notepad; INSTANCE:1]")
Send("This is the first instance of the window")
sleep(500)
WinWait("[CLASS:Notepad; INSTANCE:2]")
ConsoleWrite("Activated second: " & WinActivate("[CLASS:Notepad; INSTANCE:2]") & @LF)
WinWaitActive("[CLASS:Notepad; INSTANCE:1]")
Send("This is the second instance of the window")
sleep(500)
WinWait("[CLASS:Notepad; INSTANCE:3]")
ConsoleWrite("Activated third: " & WinActivate("[CLASS:Notepad; INSTANCE:3]") & @LF)
WinWaitActive("[CLASS:Notepad; INSTANCE:1]")
Send("This is the third instance of the window")

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I see..

So INSTANCE refers to the order in which the windows was activated?

In such case, if there are three windows, that gets created by some application, if i wanted to identify the second window that was created, this would not be possible with the instance property - as you cannot know which one of them was the last active one, right?

So... in such case, assuming the above is true, it'd probably be more reliable to use WinList, and assume that the first window that matches the class/title/etc. is the first created window, second match is second created window, and so on?

Edit:

Scratch that, the same problem occurs there.

How unfortunate. Now I wonder, is there any other way to determine which window was created first if there exists more than one window of the same class, title, etc(nothing that tells them appart)?

Edited by FreeFry

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

try running this from SciTE to show what happens to the instance number:

Opt("WinTitleMatchMode", 4)
Opt("TrayIconDebug", 1)
Run("notepad.exe")
Sleep(1000)
$h1 = WinGetHandle("[CLASS:Notepad]")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $h1 = ' & $h1 & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
Send("1")
Run("notepad.exe")
Sleep(1000)
$h2 = WinGetHandle("[CLASS:Notepad]")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $h2 = ' & $h2 & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
Send("2")
Run("notepad.exe")
Sleep(1000)
$h3 = WinGetHandle("[CLASS:Notepad]")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $h3 = ' & $h3 & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
Send("3")
Sleep(3000)
;
WinActivate($h1)
ListWin()
WinActivate($h2)
ListWin()
WinActivate($h3)
ListWin()
;
Func ListWin()
    ConsoleWrite("---" & @CRLF)
    For $x = 1 to 3
        ConsoleWrite("Instance: " & $x & " - " & WinGetHandle("[CLASS:Notepad; INSTANCE:" & $x & "]") & @CRLF)
    Next
EndFunc

It is using the ZORDER of the windows.

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Yes, but that's in a controlled environment, ie. you're controlling when to launch the process that creates the other window, and getting the handle of the most recent one.

But what if a program launches(either by user or by script), then the program creates three identical windows in all ways(except that their handles will be different of course)?

Unless I've missed something one cannot tell which window was created first in this case?

Share this post


Link to post
Share on other sites

Nothing that I can think of. The order of INSTANCE is controlled by the order the windows are activated.

Sorry if I don't have to reiterate the obvious.


[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]

Share this post


Link to post
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
Sign in to follow this  
Followers 0