WindowAction>3,... on any IE Window Doesn't Close It
Moderators: JRL, Dorian (MJT support)
-
- Macro Veteran
- Posts: 260
- Joined: Fri Apr 15, 2005 8:32 am
WindowAction>3,... on any IE Window Doesn't Close It
Has anyone else run into this issue, or is it just me?
Instead, I have to use:
Press CTRL
Send>w
Release CTRL
Instead, I have to use:
Press CTRL
Send>w
Release CTRL
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
-
- Macro Veteran
- Posts: 260
- Joined: Fri Apr 15, 2005 8:32 am
-
- Macro Veteran
- Posts: 260
- Joined: Fri Apr 15, 2005 8:32 am
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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). "
"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]
[email protected]
-
- Macro Veteran
- Posts: 260
- Joined: Fri Apr 15, 2005 8:32 am
-
- Macro Veteran
- Posts: 260
- Joined: Fri Apr 15, 2005 8:32 am
This one was interesting. I replicated not being able to close an IE window with MS.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). "
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
Monkster
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?
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]
[email protected]
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.
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]
[email protected]