Click to See Complete Forum and Search --> : Where to capture the WM_CLOSE events.


yuren
June 15th, 2001, 07:29 PM
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!

vchapran
June 15th, 2001, 07:41 PM
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

John G Duffy
June 16th, 2001, 08:35 AM
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