X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cc3bb83d947be6bd6b70fa1c5a9e4a71819a485f..f1d5aa4eca541a2f90044a63f555985d6bd4adf3:/samples/mfc/mfctest.cpp diff --git a/samples/mfc/mfctest.cpp b/samples/mfc/mfctest.cpp index 42aeae4726..245feb580c 100644 --- a/samples/mfc/mfctest.cpp +++ b/samples/mfc/mfctest.cpp @@ -32,12 +32,27 @@ // normally this shouldn't be needed any longer, i.e. it works without // it for me (VZ) // -// (2) You should link with MFC DLL, not static libraries - -// suppress warning about WINVER not being defined from MFC -#ifndef WINVER -#define WINVER 0x7000 -#endif +// (2) You should link with MFC DLL, not static libraries: or, to use static +// run-time libraries, use this command for both building wxWidgets and +// the sample: +// +// 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 +// +// (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" @@ -73,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(); }; @@ -111,14 +130,14 @@ IMPLEMENT_APP_NO_MAIN(MyApp) CMainWindow::CMainWindow() { - LoadAccelTable( "MainAccelTable" ); - Create( NULL, "Hello Foundation Application", - WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" ); + LoadAccelTable( _T("MainAccelTable") ); + Create( NULL, _T("Hello Foundation Application"), + WS_OVERLAPPEDWINDOW, rectDefault, NULL, _T("MainMenu") ); } void CMainWindow::OnPaint() { - CString s = "Hello, Windows!"; + CString s = _T("Hello, Windows!"); CPaintDC dc( this ); CRect rect; @@ -132,13 +151,13 @@ void CMainWindow::OnPaint() void CMainWindow::OnAbout() { - CDialog about( "AboutBox", this ); + CDialog about( _T("AboutBox"), this ); about.DoModal(); } void CMainWindow::OnTest() { - wxMessageBox("This is a wxWidgets message box.\nWe're about to create a new wxWidgets frame.", "wxWidgets", wxOK); + wxMessageBox(_T("This is a wxWidgets message box.\nWe're about to create a new wxWidgets frame."), _T("wxWidgets"), wxOK); wxGetApp().CreateFrame(); } @@ -169,7 +188,7 @@ BOOL CTheApp::InitInstance() wxSetInstance(m_hInstance); wxApp::m_nCmdShow = m_nCmdShow; int argc = 0; - char **argv = NULL; + wxChar **argv = NULL; wxEntryStart(argc, argv); if ( !wxTheApp || !wxTheApp->CallOnInit() ) return FALSE; @@ -208,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 = wx_static_cast(wxEventLoop *, wxEventLoop::GetActive()); if ( evtLoop && evtLoop->PreProcessMessage(msg) ) return TRUE; @@ -226,23 +246,32 @@ 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() { - MyChild *subframe = new MyChild(NULL, "Canvas Frame", wxPoint(10, 10), wxSize(300, 300), + MyChild *subframe = new MyChild(NULL, _T("Canvas Frame"), wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE); - subframe->SetTitle("wxWidgets canvas frame"); + subframe->SetTitle(_T("wxWidgets canvas frame")); // Give it a status line subframe->CreateStatusBar(); @@ -250,12 +279,12 @@ wxFrame *MyApp::CreateFrame() // Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(HELLO_NEW, "&New MFC Window"); - file_menu->Append(HELLO_QUIT, "&Close"); + file_menu->Append(HELLO_NEW, _T("&New MFC Window")); + file_menu->Append(HELLO_QUIT, _T("&Close")); wxMenuBar *menu_bar = new wxMenuBar; - menu_bar->Append(file_menu, "&File"); + menu_bar->Append(file_menu, _T("&File")); // Associate the menu bar with the frame subframe->SetMenuBar(menu_bar); @@ -266,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; @@ -300,7 +329,7 @@ void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) dc.DrawEllipse(250, 250, 100, 50); dc.DrawLine(50, 230, 200, 230); - dc.DrawText("This is a test string", 50, 230); + dc.DrawText(_T("This is a test string"), 50, 230); } // This implements a tiny doodling program! Drag the mouse using @@ -342,7 +371,7 @@ MyChild::~MyChild() void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) { - Close(TRUE); + Close(true); } void MyChild::OnNew(wxCommandEvent& WXUNUSED(event))