Where to capture the WM_CLOSE events.
Hi, Dear all,
I am confusing about how to capture the event when I close a MDI application using the "X" button on the top-rihgt corner of the window.
The whole thing I want to do is like this: just like any windows application, if a document is dirted, I want to pop out an message box when closing the application, say, yes, no, and cancel. And I am trying to capture this event in MDIForm_Unload, but it seems that the window will always be unloaded.
Thank you for your help to a beginner in VB.
Yuren
love programming!
Re: Where to capture the WM_CLOSE events.
This is done in QueryUnload event. You analize condition, and if you do not want to unload just set Cancel = True. Something like:
private Sub MDIForm_QueryUnload(Cancel as Integer, UnloadMode as Integer)
Dim Msg ' Declare variable.
' set the message text.
Msg = "Do you really want to exit the application?"
' If user clicks the No button, stop QueryUnload.
If MsgBox(Msg, vbQuestion + vbYesNo, me.Caption) = vbNo then Cancel = true
End Sub
HTH
Vlad
Re: Where to capture the WM_CLOSE events.
Capture the Close event in the CHILDS Query_Unload event and ask the question there. This event will be entered for each open child form when you click the big X
John G