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
Printable View
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
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
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.
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.
DestroyWindow does not work on an external thread, however I believe WM_DESTROY will.
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