X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/17b74d79adcc7bbd5cff4ed500e267289c0083a7..830efc9b0cb87eae22d4435af7858175017522ab:/samples/mfc/mfctest.cpp?ds=inline diff --git a/samples/mfc/mfctest.cpp b/samples/mfc/mfctest.cpp index 26e03e26fb..7121cc136c 100644 --- a/samples/mfc/mfctest.cpp +++ b/samples/mfc/mfctest.cpp @@ -26,14 +26,29 @@ // initially as the main frame, and allows wxWindows frames to be // created subsequently: // -// (1) Make MyApp::OnInit return NULL, not create a window. +// (1) Make MyApp::OnInit return FALSE, not creating a window. // (2) Restore the MFC code to create a window in InitInstance, and remove // creation of CDummyWindow. // -// IMPORTANT NOTE: to compile this sample, you must first edit -// wx/src/msw/wx_main.cc, set NOWINMAIN to 1, and remake wxWindows -// (it only needs to recompile wx_main.cc). -// This eliminates the duplicate WinMain function which MFC implements. +// IMPORTANT NOTES: +// +// (1) You need to set wxUSE_MFC to 1 in include/wx/msw/setup.h, which switches +// off some debugging features and also removes the windows.h inclusion +// in wxprec.h (MFC headers don't like this to have been included previously). +// Then recompile wxWindows and this sample. +// +// (2) 10/3/2000, wxWindows 2.1.14: unfortunately there is an assert when +// the sample tries to create an MFC window. Any suggestions welcome. It may be +// a problem with conflicting project settings. Ignoring the assert (several times) +// allows the sample to continue. In release mode the asserts don't happen. +// +// (3) I can't get the sample to link using a static MFC library, only the DLL +// version. Perhaps someone else is a wizard at working out the required settings +// in the wxWin library and the sample; then debugging the assert problem may be +// easier. +// +// (4) Compiling wxWindows in DLL mode currently includes windows.h, so you must only +// try linking wxWindows statically. // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -44,6 +59,10 @@ #include "wx/wx.h" +#if defined(_WINDOWS_) || !wxUSE_MFC +#error Sorry, you need to edit include/wx/msw/setup.h, set wxUSE_MFC to 1, and recompile. +#endif + #ifdef new #undef new #endif @@ -74,8 +93,6 @@ class MyApp: public wxApp wxFrame *CreateFrame(void); }; -DECLARE_APP(MyApp) - class MyCanvas: public wxScrolledWindow { public: @@ -91,7 +108,6 @@ class MyChild: public wxFrame MyCanvas *canvas; MyChild(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size, const long style); ~MyChild(void); - bool OnClose(void); void OnQuit(wxCommandEvent& event); void OnNew(wxCommandEvent& event); @@ -104,10 +120,6 @@ DECLARE_EVENT_TABLE() long xpos = -1; long ypos = -1; -// Initialise this in OnInit, not statically -wxPen *red_pen; -wxFont *small_font; - // ID for the menu quit command #define HELLO_QUIT 1 #define HELLO_NEW 2 @@ -122,9 +134,9 @@ IMPLEMENT_APP(MyApp) // CMainWindow::CMainWindow() { - LoadAccelTable( "MainAccelTable" ); - Create( NULL, "Hello Foundation Application", - WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" ); + LoadAccelTable( "MainAccelTable" ); + Create( NULL, "Hello Foundation Application", + WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" ); } // OnPaint: @@ -136,16 +148,16 @@ CMainWindow::CMainWindow() // void CMainWindow::OnPaint() { - CString s = "Hello, Windows!"; - CPaintDC dc( this ); - CRect rect; - - GetClientRect( rect ); - dc.SetTextAlign( TA_BASELINE | TA_CENTER ); - dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) ); - dc.SetBkMode(TRANSPARENT); - dc.TextOut( ( rect.right / 2 ), ( rect.bottom / 2 ), - s, s.GetLength() ); + CString s = "Hello, Windows!"; + CPaintDC dc( this ); + CRect rect; + + GetClientRect( rect ); + dc.SetTextAlign( TA_BASELINE | TA_CENTER ); + dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) ); + dc.SetBkMode(TRANSPARENT); + dc.TextOut( ( rect.right / 2 ), ( rect.bottom / 2 ), + s, s.GetLength() ); } // OnAbout: @@ -158,8 +170,8 @@ void CMainWindow::OnPaint() // void CMainWindow::OnAbout() { - CDialog about( "AboutBox", this ); - about.DoModal(); + CDialog about( "AboutBox", this ); + about.DoModal(); } void CMainWindow::OnTest() @@ -178,11 +190,11 @@ void CMainWindow::OnTest() // receive no arguments and are void of return type, e.g., "void OnAbout()". // BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd ) - //{{AFX_MSG_MAP( CMainWindow ) - ON_WM_PAINT() - ON_COMMAND( IDM_ABOUT, OnAbout ) - ON_COMMAND( IDM_TEST, OnTest ) - //}}AFX_MSG_MAP + //{{AFX_MSG_MAP( CMainWindow ) + ON_WM_PAINT() + ON_COMMAND( IDM_ABOUT, OnAbout ) + ON_COMMAND( IDM_TEST, OnTest ) + //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -197,16 +209,16 @@ END_MESSAGE_MAP() // BOOL CTheApp::InitInstance() { - TRACE( "HELLO WORLD\n" ); + TRACE( "HELLO WORLD\n" ); - SetDialogBkColor(); // hook gray dialogs (was default in MFC V1) + SetDialogBkColor(); // hook gray dialogs (was default in MFC V1) wxEntry((WXHINSTANCE) m_hInstance, (WXHINSTANCE) m_hPrevInstance, m_lpCmdLine, m_nCmdShow, FALSE); /* - m_pMainWnd = new CMainWindow(); - m_pMainWnd->ShowWindow( m_nCmdShow ); - m_pMainWnd->UpdateWindow(); + m_pMainWnd = new CMainWindow(); + m_pMainWnd->ShowWindow( m_nCmdShow ); + m_pMainWnd->UpdateWindow(); */ if (wxTheApp && wxTheApp->GetTopWindow()) @@ -214,11 +226,13 @@ BOOL CTheApp::InitInstance() m_pMainWnd = new CDummyWindow((HWND) wxTheApp->GetTopWindow()->GetHWND()); } - return TRUE; + return TRUE; } int CTheApp::ExitInstance() { + // OnExit isn't called by CleanUp so must be called explicitly. + wxTheApp->OnExit(); wxApp::CleanUp(); return CWinApp::ExitInstance(); @@ -252,12 +266,6 @@ bool MyApp::OnInit(void) // Don't exit app when the top level frame is deleted // SetExitOnFrameDelete(FALSE); - // Create a red pen - red_pen = new wxPen("RED", 3, wxSOLID); - - // Create a small font - small_font = new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL); - wxFrame* frame = CreateFrame(); return TRUE; } @@ -289,8 +297,7 @@ wxFrame *MyApp::CreateFrame(void) subframe->GetClientSize(&width, &height); MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height)); - wxCursor *cursor = new wxCursor(wxCURSOR_PENCIL); - canvas->SetCursor(*cursor); + canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); subframe->canvas = canvas; // Give it scrollbars @@ -317,7 +324,7 @@ void MyCanvas::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); - dc.SetFont(* small_font); + dc.SetFont(* wxSWISS_FONT); dc.SetPen(* wxGREEN_PEN); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); @@ -339,14 +346,13 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event) { wxClientDC dc(this); dc.SetPen(* wxBLACK_PEN); - long x, y; - event.Position(&x, &y); + wxPoint pos = event.GetPosition(); if (xpos > -1 && ypos > -1 && event.Dragging()) { - dc.DrawLine(xpos, ypos, x, y); + dc.DrawLine(xpos, ypos, pos.x, pos.y); } - xpos = x; - ypos = y; + xpos = pos.x; + ypos = pos.y; } BEGIN_EVENT_TABLE(MyChild, wxFrame) @@ -383,12 +389,6 @@ void MyChild::OnActivate(wxActivateEvent& event) canvas->SetFocus(); } -bool MyChild::OnClose(void) -{ - return TRUE; -} - - // Dummy MFC window for specifying a valid main window to MFC, using // a wxWindows HWND. CDummyWindow::CDummyWindow(HWND hWnd):CWnd()