 |

10-11-2003, 10:32 AM
|
|
Newcomer
|
|
Join Date: Sep 2003
Location: Birmingham UK
Posts: 10
|
|
how to close a window by giving hwnd
|
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
Quote: Originally Posted by MathImagics 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 
|
|

10-11-2003, 10:45 AM
|
 |
Algorithms 'R' Us
Forum Leader * Guru *
|
|
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
|
|
Code:
Public Const WM_SYSCOMMAND = &H112
Public Const SC_CLOSE = &HF060&
PostMessage tWindow, WM_SYSCOMMAND, SC_CLOSE, ByVal 0
Works fine for IExplore windows 
|
__________________
Sept, 2006: 2 ^ 232,582,657 - 1 is prime!
At first, I was iridescent. Then, I became transparent. Finally, I was absent.
|

10-11-2003, 11:01 AM
|
|
Newcomer
|
|
Join Date: Sep 2003
Location: Birmingham UK
Posts: 10
|
|
help!
cheers mathimagics,
could you please give me a full example cus im a newbie
cheer, tom
Quote: Originally Posted by MathImagics
Code:
Public Const WM_SYSCOMMAND = &H112
Public Const SC_CLOSE = &HF060&
PostMessage tWindow, WM_SYSCOMMAND, SC_CLOSE, ByVal 0
Works fine for IExplore windows 
|
|

10-11-2003, 12:12 PM
|
 |
Algorithms 'R' Us
Forum Leader * Guru *
|
|
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
|
|
The code I gave you has only 2 things missing - the API declaration for PostMessage, which is
Code:
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
|
__________________
Sept, 2006: 2 ^ 232,582,657 - 1 is prime!
At first, I was iridescent. Then, I became transparent. Finally, I was absent.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|