From bb2775b9e8bc1b882d9a5c7ffe68371717b9e5dc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 1 Nov 2006 21:53:30 +0000 Subject: [PATCH] override ExitMainLoop() to exit the MFC main loop instead of wxWidgets one, otherwise the application hangs on exit git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42924 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/mfc/mfctest.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/samples/mfc/mfctest.cpp b/samples/mfc/mfctest.cpp index 2712c716c1..7a3f3d34e4 100644 --- a/samples/mfc/mfctest.cpp +++ b/samples/mfc/mfctest.cpp @@ -75,6 +75,10 @@ class MyApp: public wxApp public: virtual bool OnInit(); + // we need to override this as the default behaviour only works when we're + // running wxWidgets main loop, not MFC one + virtual void ExitMainLoop(); + wxFrame *CreateFrame(); }; @@ -229,14 +233,20 @@ BOOL CTheApp::OnIdle(LONG WXUNUSED(lCount)) bool MyApp::OnInit() { #if !START_WITH_MFC_WINDOW - - // Exit app when the top level frame is deleted - SetExitOnFrameDelete(TRUE); + // as we're not inside wxWidgets main loop, the default logic doesn't work + // in our case and we need to do this explicitly + SetExitOnFrameDelete(true); (void) CreateFrame(); #endif - return TRUE; + return true; +} + +void MyApp::ExitMainLoop() +{ + // instead of existing wxWidgets main loop, terminate the MFC one + ::PostQuitMessage(0); } wxFrame *MyApp::CreateFrame() @@ -268,7 +278,7 @@ wxFrame *MyApp::CreateFrame() MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height)); canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); subframe->canvas = canvas; - subframe->Show(TRUE); + subframe->Show(true); // Return the main frame window return subframe; @@ -344,7 +354,7 @@ MyChild::~MyChild() void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) { - Close(TRUE); + Close(true); } void MyChild::OnNew(wxCommandEvent& WXUNUSED(event))