Extract reusable part of the MFC sample in a header

Allow reusing this functionality from outside the library, it can he
useful if an MFC window needs to be embedded into a wx application (or
vice versa).

Also use a better wxEntryStart() overload as a side effect, this should,
in particular, fix the problem with command line arguments processing in
mixed MFC/wx applications pointed out in a comment in the sample
previously.
This commit is contained in:
Vadim Zeitlin
2017-12-03 17:50:18 +01:00
parent ff96ebb616
commit acf53800fc
3 changed files with 166 additions and 126 deletions

View File

@@ -9,11 +9,7 @@
#ifndef __MFCTEST_H__
#define __MFCTEST_H__
/////////////////////////////////////////////////////////////////////////////
// CMainWindow:
// See hello.cpp for the code to the member functions and the message map.
//
// CMainWindow: just a normal MFC window class.
class CMainWindow : public CFrameWnd
{
public:
@@ -31,30 +27,30 @@ private:
class wxNativeContainerWindow* m_containerWX;
};
// A dummy CWnd pointing to a wxWindow's HWND
class CDummyWindow: public CWnd
#if START_WITH_MFC_WINDOW
// There is no need to define an application class if the default behaviour of
// using the wxWindow created in wxApp::OnInit() as main window is acceptable,
// but if we want to create the initial window in MFC, we need this class in
// order to override InitMainWnd() in it.
class SampleMFCWinApp : public wxMFCWinApp
{
public:
CDummyWindow(HWND hWnd);
~CDummyWindow(void);
protected:
BOOL InitMainWnd() wxOVERRIDE
{
// Demonstrate creation of an initial MFC main window.
m_pMainWnd = new CMainWindow();
m_pMainWnd->ShowWindow( m_nCmdShow );
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
/////////////////////////////////////////////////////////////////////////////
#else // !START_WITH_MFC_WINDOW
// CTheApp:
//
class CTheApp : public CWinApp
{
public:
BOOL InitInstance();
int ExitInstance();
typedef wxMFCWinApp SampleMFCWinApp;
// Override this to provide wxWidgets message loop
// compatibility
BOOL PreTranslateMessage(MSG *msg);
BOOL OnIdle(LONG lCount);
};
/////////////////////////////////////////////////////////////////////////////
#endif // START_WITH_MFC_WINDOW/!START_WITH_MFC_WINDOW
#endif // __MFCTEST_H__