how to close a window by giving hwnd

tombrum
10-11-2003, 11:32 AM
Hi all, i wonder if someone can give me an example of a working WM_SYSCOMMAND in action closing down internet explorer. If you can i would be very very gratefull

I believe that, in the general case of closing other application windows, it's possible that the target application might not do all its normal shutdown processing if you simply post a WM_CLOSE.

The best method, I think, is to post a WM_SYSCOMMAND with the SC_CLOSE parameter - this is the closest you can get to a simulation of the user clicking on the X (Close) button of the window.

And whichever way you do it, as Red Bull has noted, it should be Posted, not Sent.


Dr Memory :cool:

Mathimagics
10-11-2003, 11:45 AM
Public Const WM_SYSCOMMAND = &H112
Public Const SC_CLOSE = &HF060&

PostMessage tWindow, WM_SYSCOMMAND, SC_CLOSE, ByVal 0


Works fine for IExplore windows :cool:

tombrum
10-11-2003, 12:01 PM
cheers mathimagics,

could you please give me a full example cus im a newbie :o

cheer, tom

Public Const WM_SYSCOMMAND = &H112
Public Const SC_CLOSE = &HF060&

PostMessage tWindow, WM_SYSCOMMAND, SC_CLOSE, ByVal 0


Works fine for IExplore windows :cool:

Mathimagics
10-11-2003, 01:12 PM
The code I gave you has only 2 things missing - the API declaration for PostMessage, which is

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

and tWindow.

You need to set this to the handle of the window you want to close.

Search for FindWindow - heaps of examples. And it looks like the poster of this thread was looking for IExplore windows so you could send him a PM maybe

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum