CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2000
    Location
    OH
    Posts
    34

    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!

  2. #2
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    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


  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured