X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ff96483989dfd0649360c704e16d01601e3b070d..e2517f176b1739431be7fb21d120226e2311ded2:/samples/mfc/mfctest.cpp diff --git a/samples/mfc/mfctest.cpp b/samples/mfc/mfctest.cpp index 2712c716c1..a4102648a9 100644 --- a/samples/mfc/mfctest.cpp +++ b/samples/mfc/mfctest.cpp @@ -38,8 +38,21 @@ // // nmake -f makefile.vc BUILD=debug SHARED=0 DEBUG_RUNTIME_LIBS=0 RUNTIME_LIBS=static all // -// Unless the run-time library settings match for wxWidgets and MFC, you will get -// link errors for symbols such as __mbctype, __argc, and __argv +// Unless the run-time library settings match for wxWidgets and MFC, you +// will get link errors for symbols such as __mbctype, __argc, and __argv +// +// (3) If you see bogus memory leaks within the MSVC IDE on exit, in this +// sample or in your own project, you must be using __WXDEBUG__ + +// WXUSINGDLL + _AFXDLL +// Unfortunately this confuses the MSVC/MFC leak detector. To do away with +// these bogus memory leaks, add this to the list of link objects, make it +// first: mfc[version][u]d.lib +// - [version] -> 42 or 70 or 80 etc +// - u if using Unicode +// +// (4) Unicode builds may produce the linker error "unresolved external symbol _WinMain@16". +// MFC requires you to manually add the Unicode entry point to the linker settings, +// Entry point symbol -> wWinMainCRTStartup #include "stdafx.h" @@ -75,6 +88,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(); }; @@ -210,7 +227,8 @@ int CTheApp::ExitInstance() // Override this to provide wxWidgets message loop compatibility BOOL CTheApp::PreTranslateMessage(MSG *msg) { - wxEventLoop *evtLoop = wxEventLoop::GetActive(); + wxEventLoop * const + evtLoop = static_cast(wxEventLoop::GetActive()); if ( evtLoop && evtLoop->PreProcessMessage(msg) ) return TRUE; @@ -228,15 +246,24 @@ BOOL CTheApp::OnIdle(LONG WXUNUSED(lCount)) bool MyApp::OnInit() { -#if !START_WITH_MFC_WINDOW + if ( !wxApp::OnInit() ) + return false; - // Exit app when the top level frame is deleted - SetExitOnFrameDelete(TRUE); +#if !START_WITH_MFC_WINDOW + // 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 +295,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 +371,7 @@ MyChild::~MyChild() void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) { - Close(TRUE); + Close(true); } void MyChild::OnNew(wxCommandEvent& WXUNUSED(event))