WindowAction>3,... on any IE Window Doesn't Close It

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

WindowAction>3,... on any IE Window Doesn't Close It

Post by fightcancer » Thu Aug 11, 2005 11:44 pm

Has anyone else run into this issue, or is it just me?

Instead, I have to use:


Press CTRL
Send>w
Release CTRL

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Aug 12, 2005 1:25 am

Just to be sure, you are including the window title, correct?

WindowAction>3.WindowName*
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Sun Aug 14, 2005 3:28 am

yes I do include the name of the window. I've tried w/ and w/o wildcards on a number of IE 6.0.X windows. Maybe it's just my system....

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Mon Aug 15, 2005 12:32 am

I duplicated this peculiarity on a second PC w/IE 6.0.X SP2.

Maybe IE windows are just too strong.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Aug 15, 2005 2:03 pm

Please submit sample code that includes the WindowAction line and some of the lines that preceed it.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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

Post by support » Mon Aug 15, 2005 4:32 pm

WindowAction>3 does the same as CloseWindow. It sends WM_CLOSE to the window in question. This is the message that windows sends to application when it is to close. But we cannot guarantee that all windows will close when sent this message from another application. The help file says this:

"Please note: this command simply sends the internal Windows WM_CLOSE message to the target window. This is the internal instruction to tell the window to close. However, applications all interpret this instruction differently and there is no guarantee that it will cause the window to close. If CloseWindow fails to close the window we recommend simulating user input to close it instead (e.g. by sending ALT-F4 or equivalent). "
MJT Net Support
[email protected]

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Wed Aug 24, 2005 1:21 am

good point. Thanks Support.

Bob, sorry about not responding earlier. I suffered an untimely hard drive crash and am just today getting back on my feet.

I'll try to duplicate on this new, fresh XP installation ASAP and post results.

Thanks again for the help.

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Wed Aug 31, 2005 9:23 pm

MS 7.3.11.4e

For those interested, I got my PC working again. On the fresh installation of XP SP2 w/IE6 SP2, WindowsAction>3,* does NOT close IE windows.

That's OK though as we can use Ctrl + W or Alt + F4 as a substitute.

User avatar
Monkster
Junior Coder
Posts: 42
Joined: Fri Oct 04, 2002 9:37 pm
Location: On an Island with Wilson

Post by Monkster » Wed Aug 31, 2005 11:23 pm

support wrote:WindowAction>3 does the same as CloseWindow. It sends WM_CLOSE to the window in question. This is the message that windows sends to application when it is to close. But we cannot guarantee that all windows will close when sent this message from another application. The help file says this:

"Please note: this command simply sends the internal Windows WM_CLOSE message to the target window. This is the internal instruction to tell the window to close. However, applications all interpret this instruction differently and there is no guarantee that it will cause the window to close. If CloseWindow fails to close the window we recommend simulating user input to close it instead (e.g. by sending ALT-F4 or equivalent). "
This one was interesting. I replicated not being able to close an IE window with MS.

Yes, I actually fired up IE! ( http://www.getfirefox.com )

At first I thought Microsloth may have disabled the WM_CLOSE
message (in an attempt to get around the endless barrage of
IE hackers), but...

Using XP SP2, IE 6 SP2 and VB6 I tried this:
(new vb project with a module and a form with a command button)

'Module declarations
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long

Public Const WM_CLOSE = &H10

'Module code
Public Sub CloseIEWindow(ByVal hWnd As Long)
Dim lRet As Long
lRet = PostMessage(hWnd, WM_CLOSE, 0&, 0&)
End Sub

'Form code
Private Sub Command1_Click()
Dim hwndIE As Long
'get the hwnd for the (particular) IE window I want to close
hwndIE = FindWindow(vbNullString, "Google - Microsoft Internet Explorer")
'close the IE window
CloseIEWindow hwndIE
End Sub

I ran the program, clicked the command button and the IE window closed.
Seems that WM_CLOSE should work no matter what language it is used in?
There's probably more to it but... just an observation :)

BTW it works in Delphi too...

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
myh: HWND;
begin
myh := FindWindow(nil, 'Google - Microsoft Internet Explorer');
if myh 0 then PostMessage(myh, WM_CLOSE, 0, 0);
end;

end.
Best Wishes,
Monkster

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

Post by support » Thu Sep 01, 2005 9:18 am

That's bizarre, because that is exactly what CloseWindow does!

Perhaps CloseWindow is getting wrong window handle due to unspecific window title - try issuing exact window title or use window handle instead?
MJT Net Support
[email protected]

User avatar
Monkster
Junior Coder
Posts: 42
Joined: Fri Oct 04, 2002 9:37 pm
Location: On an Island with Wilson

Post by Monkster » Fri Sep 02, 2005 4:41 pm

I tried using the exact window title, no joy.

I'm probably going off topic (my apologies) but what is the method to determine a windows handle (hwnd) in MS?

Thank you for the most versatile and excellent macro product available! :o
Best Wishes,
Monkster

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

Post by support » Fri Sep 02, 2005 4:53 pm

Turns out we were using SendMessage, rather than PostMessage. SendMessage waits for the message to be processed while PostMessage puts the message in the queue and returns.

I tried CloseWindow>Microsoft Internet Explorer* using both the old (SendMessage) version and the new (PostMessage). Old fails, new works. So that appears to be the answer. So that will be in the 7.4 release. So consider it fixed.

To use window handles set WIN_USEHANDLE to 1. GetActiveWindow, for example, will now return a window handle and you can then use that handle in any of the window functions.
MJT Net Support
[email protected]

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