|
-
Aug 8th, 2002, 07:33 AM
#1
Closing a window via it's hwnd
um how can i close a window by it's hwnd.. the only way i no is 2 use:
SendMessage TempWinHwnd, WM_CLOSE....
but this won't close explorer and folder windows..
Thanks in advance
Kris
-
Aug 8th, 2002, 08:49 AM
#2
Hyperactive Member
This code worked fine for me:
VB Code:
Private 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
Const WM_CLOSE = &H10
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
'Close Explorer
PostMessage FindWindow("ExploreWClass", vbNullString), WM_CLOSE, 0, 0
End Sub
Private Sub Command2_Click()
'Close Folder Browsing
PostMessage FindWindow("CabinetWClass", vbNullString), WM_CLOSE, 0, 0
End Sub
Joe
-
Aug 8th, 2002, 09:08 AM
#3
Software Eng.
But make sure you specify a window title too, otherwise windows will close the first window in the list -- which may not the be the one you wanted to.
-
Aug 8th, 2002, 09:14 AM
#4
Hyperactive Member
I think it's
DestroyWindow Hwnd
I don't know it's declaration though, not sure what it does, but it seems to work fine.
-
Aug 8th, 2002, 09:21 AM
#5
Software Eng.
DestroyWindow does not work on an external thread, however I believe WM_DESTROY will.
-
Aug 8th, 2002, 09:22 AM
#6
Hyperactive Member
DestroyWindow is a much harsher way of shutting a program down; it sends the WM_DESTROY and WM_NCDESTROY messages which are almost equivalent to "end tasking" an application. This means time is not allocated for cleanup procedures and may end up in leaks. I would still advise using the code I posted(and as megatron said specify a title; I did not merely to demonstrate the simplest code that works).
Joe
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|