]> git.saurik.com Git - wxWidgets.git/commitdiff
provide an example implementation of wxCloseEvent handler
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Mon, 24 Nov 2008 00:01:37 +0000 (00:01 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Mon, 24 Nov 2008 00:01:37 +0000 (00:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56949 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/event.h

index 88f3714d07562dd5ca2216f19c02364d5e7896af..2db11fddb5792aa3dd8856089619c8fabb6d1a94 100644 (file)
@@ -2861,6 +2861,27 @@ public:
     This allows the wxWindow::Close function to return @true or @false depending
     on whether the close instruction was honoured or not.
 
+    Example of a wxCloseEvent handler:
+
+    @code
+        void MyFrame::OnClose(wxCloseEvent& event)
+        {
+            if ( event.CanVeto() && m_bFileNotSaved )
+            {
+                if ( wxMessageBox("The file has not been saved... continue closing?",
+                                  "Please confirm",
+                                  wxICON_QUESTION | wxYES_NO) != wxYES )
+                {
+                    event.Veto();
+                    return;
+                }
+            }
+
+            Destroy();  // you may also do:  event.Skip();
+                        // since the default event handler does call Destroy(), too
+        }
+    @endcode
+
     The EVT_END_SESSION event is slightly different as it is sent by the system
     when the user session is ending (e.g. because of log out or shutdown) and
     so all windows are being forcefully closed. At least under MSW, after the