Try WM_QUIT.
Printable View
Try WM_QUIT.
Yes, tried but of no use. Or maybe I ma not using the right sequence. What's the right sequence? I will the post the code in a few minutes.
I will post the code a little later(hour or two) as i have to go for
some urgent work right now.
The correct order should be:
WM_CLOSE
WM_DESTROY
WM_NCDESTROY
WM_QUIT
Still doesn't work in some cases. I have explained in the comments
Code:Option Explicit
Private Declare Function DestroyWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Dim lngHwndMsgBox As Long
Dim lngRV As Long
Private Const WM_CLOSE = &H10
Private Const WM_DESTROY = &H2
Private Const WM_NCDESTROY = &H82
Private Const WM_QUIT = &H12
Private Sub Command1_Click()
lngHwndMsgBox = FindWindowEx(0&, 0&, vbNullString, "Test MsgBox")
'Send Message with WM_CLOSE
'works on vbOkOnly,vbOkCancel,vbYesNoCancel & vbRetryCancel buttons MsgBox
'All the above working MsgBox conditions have "Esc" key enabled
'doesnot work on vbAbortRetryIgnore and vbYesNo
'lngRV = SendMessage(lngHwndMsgBox, WM_CLOSE, 0&, 0&)
'Kills all MsgBoxes, but the application stops responding
lngRV = SendMessage(lngHwndMsgBox, WM_CLOSE, 0&, 0&)
lngRV = SendMessage(lngHwndMsgBox, WM_DESTROY, 0&, 0&)
lngRV = SendMessage(lngHwndMsgBox, WM_NCDESTROY, 0&, 0&)
lngRV = SendMessage(lngHwndMsgBox, WM_QUIT, 0&, 0&)
End Sub
Any ideas. Do I need to put it in a Do..While loop
What do you want to do? If you want to click a button may use once you have the hwnd of the button:
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
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const MK_LBUTTON = &H1
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private Const MK_RBUTTON = &H2
Yes, thats certainly a way. I can even send a BM_CLICK message to the command button. But what i want to know is why does it work in some cases, while in others it doesn't.
I cam confirm the behaviour, and even tried it in a do while loop, but still no luck closing msgboxes using that approach.
amitabh,
I found out why...:cool:
Sending the wm_close to the window is the equivalent of clicking the "x" on the form.
Now, check out the state of the "x" on a vbyesno message box...it is disabled, so you can't close such a message box this way.
You will have to find the hwnd of the button and click either yes or no.
Oh good:D
Thanks
But what about WM_Quit, Wm_Destroy, WM_NCDestroy. Why aren't they working. Anyway
I have implemented this through clicking of command buttons
Perhaps you could also use:
Code:Private Declare Function TerminateProcess& Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long)