Make it possible to use an existing base class for wxMFCWinApp

When porting an existing MFC codebase to wxWidgets, it may be useful to
continue using the existing CWinApp-derived application class, so allow
deriving wxMFCApp from it instead of always deriving it from CWinApp
itself.
This commit is contained in:
Vadim Zeitlin
2017-12-08 16:42:34 +01:00
parent 042d922e88
commit 3960e630f1

View File

@@ -42,12 +42,17 @@ public:
// MFC application class forwarding everything to wxApp
// ----------------------------------------------------------------------------
class wxMFCWinApp : public CWinApp
// The template parameter here is an existing class deriving from CWinApp or,
// if there is no such class, just CWinApp itself.
template <typename T>
class wxMFCApp : public T
{
public:
typedef T BaseApp;
BOOL InitInstance() wxOVERRIDE
{
if ( !CWinApp::InitInstance() )
if ( !BaseApp::InitInstance() )
return FALSE;
if ( !wxEntryStart(m_hInstance) )
@@ -71,7 +76,7 @@ public:
wxEntryCleanup();
return CWinApp::ExitInstance();
return BaseApp::ExitInstance();
}
// Override this to provide wxWidgets message loop compatibility
@@ -82,12 +87,12 @@ public:
if ( evtLoop && evtLoop->PreProcessMessage(msg) )
return TRUE;
return CWinApp::PreTranslateMessage(msg);
return BaseApp::PreTranslateMessage(msg);
}
BOOL OnIdle(LONG lCount) wxOVERRIDE
{
BOOL moreIdle = CWinApp::OnIdle(lCount);
BOOL moreIdle = BaseApp::OnIdle(lCount);
if ( wxTheApp && wxTheApp->ProcessIdle() )
moreIdle = TRUE;
@@ -119,6 +124,8 @@ protected:
}
};
typedef wxMFCApp<CWinApp> wxMFCWinApp;
// ----------------------------------------------------------------------------
// wxWidgets application class to be used in MFC applications
// ----------------------------------------------------------------------------