IfWindowOpen jumps to False Statement

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Spudwars
Newbie
Posts: 13
Joined: Fri Dec 09, 2005 1:01 pm

IfWindowOpen jumps to False Statement

Post by Spudwars » Fri Dec 16, 2005 2:39 pm

Hi there,

I have 3 uses of IfWindowOpen. The first works, the other two jump to the False statment.

Note: If you would like the full code to look over, can you please give me an email address to send it to as I don't want to paste it ALL on here. Thank you.
Repeat>loopCount

// If Error window open, attempt closeError else attempt normal close.
IfWindowOpen>AGS Error*,closeError,closeAGS

//----------------------------------------------------------------
// Close Error Window
//----------------------------------------------------------------
Label>closeError
.......above code works........



//----------------------------------------------------------------
// Close Ags Main Window
//----------------------------------------------------------------
Label>closeAGS
IfWindowOpen>Analysis Ground Station*

GetWindowHandle>Analysis Ground Station*,analysisWindow_hwnd
Let>WIN_USEHANDLE=1
SetFocus>anaylsisWindow_hwnd
Press ALT
Send>fx
Release ALT

Else
LibFunc>user32,FindWindowA,loginWindow_hwnd,FNWNS390,

//DEBUGGING
message>Login Window Handle is set to : %loginWindow_hwnd% (%loopCount%)
Wait>3

// If Login Window is open, close it, else report an Unknown Window Error and skip AGS run but do End Report
Let>WIN_USEHANDLE=1

SetFocus>loginWindow_hwnd

Let>WF_TYPE=1

IfWindowOpen>loginWindow_hwnd,closeLogin,unknownWindow
Let>WIN_USEHANDLE=0

//----------------------------------------------------------------
// Close Ags Startup Login Window
//----------------------------------------------------------------
Label>closeLogin
........code........




//----------------------------------------------------------------
// Unknown Window Open Error
//----------------------------------------------------------------
Label>unknownWindow
// Ags.exe is running, but script cannot close it because it does not recognise / cannot find the window open.

DateStamp>%errorlog%, !Unknown Window Open Error
Note: The "SetFocus>loginWindow_hwnd" line brings the required window to the front - but then the IfWindowOpen statement takes the code to the unknownWindow label.

My work around for using the loginWindow_hwnd key is:
if>loginWindow_hwnd>0,
closeLogin,unknownWindow
...but that is tacky!

I have tried changing the WF_TYPE, I have set and unset WIN_USEHANDLE, I have changed the layout of the IF statements to be over multiple lines rather than one line statements, I have cursed...none of which have had any effect.

Help!

Thanks,
Chris

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Dec 16, 2005 3:29 pm

I'm not sure what you are saying here. What's the problem? Also, which version are you running? There was a problem with IfWindowOpen that was fixed a while back.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Spudwars
Newbie
Posts: 13
Joined: Fri Dec 09, 2005 1:01 pm

Post by Spudwars » Fri Dec 16, 2005 3:46 pm

Hiya, I'm running the new Macro Scheduler Pro v.6.0 beta 007. We do own a previous version, but I thought this would be better to play with!

My aim is to close down a program called AGS before running some code. To do this the script does the following:
1 - checks that an instance of AGS is running, and loops the following "close AGS" coding by the number of instances running.
2 - Determine if it is open with an Error Window too, if so close the error window (press ENTER to clear error)
3 - Determine if the main window is open (Analysis Ground Station*) and then close that (press ALT fx)
4 - Determine whether the AGS Login screen is open (this has no window title, hence the LibFunc code), and if this is open press ESC to exit it.
5 - If login screen AND steps 2-4 aren't actioned, then it's an Unknown Window = exit script.

The IfWindowOpen statement is used to determine the above 2,3 and 4 processes. Would you like a more complete version of the code?

The problem is that during step 3 - the main window doesn't close.

Step 5 always jumps to Unknown Window when the If login screen open (using it's handle) doesn't work.

Was that any more helpful?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Dec 16, 2005 3:51 pm

This may be getting a child or invisible window:

IfWindowOpen>Analysis Ground Station*

GetWindowHandle>Analysis Ground Station*,analysisWindow_hwnd
Let>WIN_USEHANDLE=1
SetFocus>anaylsisWindow_hwnd
Press ALT
Send>fx
Release ALT

If you are closing the main window I would just do:

//visible windows only
Let>WF_TYPE=2
SetFocus>Analysis Ground Station
Press ALT
Send>fx
Release ALT

Or could als try setting WF_TYPE=0 to avoid finding child windows

Anyway, there is no problem with IfWindowOpen. It works fine. Your issue is that you are failing to focus the correct window.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Spudwars
Newbie
Posts: 13
Joined: Fri Dec 09, 2005 1:01 pm

Post by Spudwars » Fri Dec 16, 2005 4:33 pm

Your solution does away with the IF statement. I'm only trying to close the window IF it is open - and I won't know that it is open for sure.

Focusing it isn't a problem, I can do this. And this is what I do JUST before calling the Login Window (the other instance of this problem).

I focus on it, then it calls the Ifwindowopen and it jumps to the unknownWindow label (false statement, saying it's not open - when it blatently is! It focused on it a second before hand!)

Ahh, too much confusion!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Dec 16, 2005 4:42 pm

So try this:


//visible windows only
Let>WF_TYPE=2
IfWindowOpen>Analysis Ground Station*
SetFocus>Analysis Ground Station*
Press ALT
Send>fx
Release ALT
ELSE
. ..
Endif


If it fails you should try making the window title more explicit to narrow down the search - try an exact match instead or match more of it. You can also try changing WF_TYPE=2 to WF_TYPE=0.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts