Sign in to follow this  
Followers 0
JohnB

When Does Winactivate Fail?

7 posts in this topic

#1 ·  Posted (edited)

I wrote a C++ GUI program, and am using AutoIT (3.1.1) to test it on Windows XP.

The problem I'm having is that there are a lot of windows that pop up, some of them AlwaysOnTop, and so I have to call WinActivate a lot.

$state = WinGetState("Headset")
If BitAND($state, 2) Then; Visible
   WinActivate("Headset")
   if WinWaitActive("Headset","",1) then
      DoStuff()
   else
      DisplayError()
   endif
endif

When would DisplayError() be called, given that I can *see* the window peeking out from behind others? It just doesn't activate.

Some points:

1) The window's title is always "Headset", and not "Headset " or whatever.

2) The WinTitleMatchMode option has been set to exact (3).

3) The fact that DisplayError() is called means AutoIT is finding the window, and it deems it is visible.

4) The Headset window is an Overlapped Window that is AlwaysOnTop, and it appears on the TaskBar, but then again so do others that always work fine.

5) I've increased the timeout from 1 to 5 - no luck.

When the script first starts, DoStuff() is called correctly. My program occasionally adds and removes Child Windows, resizing the Parent Window as necessary. Once this has happened, DisplayError() is always called until I physically Activate the window with the mouse myself, then move it around on the screen. DoStuff() then gets called again until the next time the window is programatically modified (but never the title).

Help! (And thanks in advance)

(Quick Edit to add "then" - thanks greenmachine!)

Edited by JohnB

Share this post


Link to post
Share on other sites



This line needs a Then at the end:

if WinWaitActive("Headset","",1)

Share this post


Link to post
Share on other sites

It occurs to me that maybe I should ask the question differently:

WinActivate is a function with no return value.

Q. Why?

A. It is assumed to work.

Q. Why then is there a WinWaitActive function?

A. If the window was minimised, then with XP's Window pop-up Animation taking time, the script could well be performing the next step before the Window has finished popping up.

Q. Why then is the timeout value expressed in *seconds*? What could possibly take seconds?

A. ???? It certainly isn't to give it time to launch an application - that would require different parameters.

Q. OK, so without poring over AutoIT code, what Messages does AutoIT send/post to a found window to make it activate?

Thanks (again) in advance! (Should I cross-post this to AutoIT developers?)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It occurs to me that maybe I should ask the question differently:

WinActivate is a function with no return value.

Q. Why?

A. It is assumed to work.

Q. Why then is there a WinWaitActive function?

A. If the window was minimised, then with XP's Window pop-up Animation taking time, the script could well be performing the next step before the Window has finished popping up.

Q. Why then is the timeout value expressed in *seconds*? What could possibly take seconds?

A. ???? It certainly isn't to give it time to launch an application - that would require different parameters.

Q. OK, so without poring over AutoIT code, what Messages does AutoIT send/post to a found window to make it activate?

Thanks (again) in advance! (Should I cross-post this to AutoIT developers?)

Whoa there, WinActivate has a return value. From the helpfile:

WinActivate Activates (gives focus to) a window.

WinActivate ( "title" [, "text"] )

Parameters

title The title of the window to activate. See Title special definition.

text [optional] The text of the window to activate.

Return Value

Success: Returns 1.

Failure: Returns 0 if window is not found.

As for the WinWaitActive function, what if you're starting a program rather than just activating it? For example: starting Microsoft Word takes longer than a second, IE takes a little longer than a second, all large games take longer than a second.... Edited by greenmachine

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

...WinActivate has a return value...

...not in AutoIt 3.1.1 - just in beta...

Edit:

MsgBox(0, "", WinActivate("jkhlkhlkh"))
Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

...not in AutoIt 3.1.1 - just in beta...

We've been having an extensive PM conversation, and I noticed that after he insisted that it doesn't have a return value. I always assume beta when I script (since that's all I use, and the helpfile I have open), and he didn't mention otherwise....

Share this post


Link to post
Share on other sites

I wrote a C++ GUI program, and am using AutoIT (3.1.1) to test it on Windows XP.

The problem I'm having is that there are a lot of windows that pop up, some of them AlwaysOnTop, and so I have to call WinActivate a lot.

$state = WinGetState("Headset")
If BitAND($state, 2) Then; Visible
   WinActivate("Headset")
   if WinWaitActive("Headset","",1) then
      DoStuff()
   else
      DisplayError()
   endif
endif

When would DisplayError() be called, given that I can *see* the window peeking out from behind others? It just doesn't activate.

Some points:

1) The window's title is always "Headset", and not "Headset " or whatever.

2) The WinTitleMatchMode option has been set to exact (3).

3) The fact that DisplayError() is called means AutoIT is finding the window, and it deems it is visible.

4) The Headset window is an Overlapped Window that is AlwaysOnTop, and it appears on the TaskBar, but then again so do others that always work fine.

5) I've increased the timeout from 1 to 5 - no luck.

When the script first starts, DoStuff() is called correctly. My program occasionally adds and removes Child Windows, resizing the Parent Window as necessary. Once this has happened, DisplayError() is always called until I physically Activate the window with the mouse myself, then move it around on the screen. DoStuff() then gets called again until the next time the window is programatically modified (but never the title).

Help! (And thanks in advance)

(Quick Edit to add "then" - thanks greenmachine!)

1) OK

2) OK

3) No, it means either is window is not active within the 1 second timeout allowed or that it does not exist.

4) Note: only 1 window can be on top.

5) OK

I see not waiting for the window before you use WinActivate so further use could cause the failure that you mention.

WinActivate is a function with no return value.

Q. Why?

A. It is assumed to work.

No, if you do not wait or check that it exists, then WinActivate is useless. There are are functions like WinExists, WinActive and others that can programmically check and continue with more chance of success then your script has done

.

Q. Why then is there a WinWaitActive function?

A. If the window was minimised, then with XP's Window pop-up Animation taking time, the script could well be performing the next step before the Window has finished popping up.

Yep, it will not progess until the window is active.

Q. Why then is the timeout value expressed in *seconds*? What could possibly take seconds?

A. ???? It certainly isn't to give it time to launch an application - that would require different parameters.

Enables pausing or if the window does never activate or wait for the window to appear active or even fails to exist then you can take alternate action to repair the event or do other.

Q. OK, so without poring over AutoIT code, what Messages does AutoIT send/post to a found window to make it activate?

Unless you adapt your script to work better, then knowing messages means perhaps little.

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