CloseWindow not working

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

CloseWindow not working

Post by Captive » Sun Aug 17, 2003 1:27 am

I have a script that opens a 'HungerSite.com' window, and clicks in a specified position. I've included a section that first makes it check to see if any existing windows for that site are open, and close them if they are.

So far, everything works except the CloseWindow command. It detects the window, it sets focus to it, but just won't close it.

To test this, first open a browser window to http://www.thehungersite.com/


SRT>CloseAnyHungerWindows
Label>CheckForHungerWin
' Close all windows starting "The Hunger Site*"
IfWindowOpen>The Hunger Site*,CloseHungerWindow
Goto>EndCloseHungerWin

Label>CloseHungerWindow
Rem>MessageModal>Found a window!
SetFocus>The Hunger Site*
Wait>2.0
GetActiveWindow>sWinTitle,iWinX,iWinY,iWinWidth,iWinHeight
Wait>0.5
Rem>MessageModal>Title: %sWinTitle%%CRLF%X=%iWinX%, Y=%iWinY%
Let>WF_TYPE=0
CloseWindow>%sWinTitle%
Wait>0.5
Goto>CheckForHungerWin

Label>EndCloseHungerWin
End>CloseAnyHungerWindows


Gosub>CloseAnyHungerWindows


Note, I've also tried things like: "CloseWindow>The Hunger *", and others, but nothing seems to work for this.

If anyone can see anything wrong in my code, please let me know.

Lumumba

Post by Lumumba » Sun Aug 17, 2003 7:44 pm

Please test if

Code: Select all

Press ALT
Press F4
Release ALT
will work.

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Mon Aug 18, 2003 6:37 am

It does, yes. My current work around was similar - press alt, send fc, release alt. Which selects file -> close.

I was hoping CloseWindow would work, and because we can specify a window name, it specifically closes that window, regardless of it being in focus or not. If another program displays a popup message, or just sets itself in focus, I don't want alt-f4 closing the wrong window.

So there appears to be a bug with CloseWindow. :cry:

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Aug 18, 2003 11:12 am

Hi,

There is no bug with CloseWindow. For the umpteenth time CloseWindow simply sends a WM_CLOSE message to the specified window. What that window does with WM_CLOSE is governed by the programmers of that application. Some applications may decide to ignore it. Some may prompt for confirmation ... we just don't know. We've even found some anomolies - for instance, if you send a WM_CLOSE (or use CloseWindow) to Microsoft Word it will close down immediately without even offering to save your changes - it just exits ungracefully and you lose your work! I'd argue that that is incorrect, but the Microsoft guys will argue that they never expected another app to send it a WM_CLOSE and that they only banked on a user clicking File/Exit (or it's associated keystroke).

At the end of the day we CAN guarantee that simulating user input to close an application, i.e. by ALT-F4, or ALT-fx for example, WILL do EXACTLY what happens when YOU press ALT-F4.

Some programmers will make the app do stuff when the exit menu is clicked, rather than when the application receives a WM_CLOSE. Think about it. Which is correct is open for argument but outside our control.

CloseWindow may work with some windows, but as it works at a lower level and bypasses the user interface, we have no way of knowing exactly how the application will respond. It's great where it works, but should be considered a bonus when it does.
MJT Net Support
[email protected]

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