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:
@@ -42,12 +42,17 @@ public:
|
|||||||
// MFC application class forwarding everything to wxApp
|
// 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:
|
public:
|
||||||
|
typedef T BaseApp;
|
||||||
|
|
||||||
BOOL InitInstance() wxOVERRIDE
|
BOOL InitInstance() wxOVERRIDE
|
||||||
{
|
{
|
||||||
if ( !CWinApp::InitInstance() )
|
if ( !BaseApp::InitInstance() )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if ( !wxEntryStart(m_hInstance) )
|
if ( !wxEntryStart(m_hInstance) )
|
||||||
@@ -71,7 +76,7 @@ public:
|
|||||||
|
|
||||||
wxEntryCleanup();
|
wxEntryCleanup();
|
||||||
|
|
||||||
return CWinApp::ExitInstance();
|
return BaseApp::ExitInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override this to provide wxWidgets message loop compatibility
|
// Override this to provide wxWidgets message loop compatibility
|
||||||
@@ -82,12 +87,12 @@ public:
|
|||||||
if ( evtLoop && evtLoop->PreProcessMessage(msg) )
|
if ( evtLoop && evtLoop->PreProcessMessage(msg) )
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
return CWinApp::PreTranslateMessage(msg);
|
return BaseApp::PreTranslateMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL OnIdle(LONG lCount) wxOVERRIDE
|
BOOL OnIdle(LONG lCount) wxOVERRIDE
|
||||||
{
|
{
|
||||||
BOOL moreIdle = CWinApp::OnIdle(lCount);
|
BOOL moreIdle = BaseApp::OnIdle(lCount);
|
||||||
|
|
||||||
if ( wxTheApp && wxTheApp->ProcessIdle() )
|
if ( wxTheApp && wxTheApp->ProcessIdle() )
|
||||||
moreIdle = TRUE;
|
moreIdle = TRUE;
|
||||||
@@ -119,6 +124,8 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef wxMFCApp<CWinApp> wxMFCWinApp;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxWidgets application class to be used in MFC applications
|
// wxWidgets application class to be used in MFC applications
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user