Destroy MFC main window when its wx counterpart is destroyed
This avoids using m_pMainWnd after its HWND becomes invalid, as this resulted in assert failures from CWnd::WalkPreTranslateTree() called with this HWND as its hWndStop argument from PreTranslateMessage() which was used to pre-translate a WM_NULL message the application sometimes received while closing down.
This commit is contained in:
@@ -122,6 +122,11 @@ protected:
|
|||||||
// running.
|
// running.
|
||||||
m_pMainWnd = new wxMFCWnd(w);
|
m_pMainWnd = new wxMFCWnd(w);
|
||||||
|
|
||||||
|
// We also need to reset m_pMainWnd when this window will be destroyed
|
||||||
|
// to prevent MFC from using an invalid HWND, which is probably not
|
||||||
|
// fatal but can result in at least asserts failures.
|
||||||
|
w->Bind(wxEVT_DESTROY, &wxMFCApp::OnMainWindowDestroyed, this);
|
||||||
|
|
||||||
// And we need to let wxWidgets know that it should exit the
|
// And we need to let wxWidgets know that it should exit the
|
||||||
// application when this window is closed, as OnRun(), which does this
|
// application when this window is closed, as OnRun(), which does this
|
||||||
// by default, won't be called when using MFC main message loop.
|
// by default, won't be called when using MFC main message loop.
|
||||||
@@ -129,6 +134,15 @@ protected:
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnMainWindowDestroyed(wxWindowDestroyEvent& event)
|
||||||
|
{
|
||||||
|
event.Skip();
|
||||||
|
|
||||||
|
delete m_pMainWnd;
|
||||||
|
m_pMainWnd = NULL;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef wxMFCApp<CWinApp> wxMFCWinApp;
|
typedef wxMFCApp<CWinApp> wxMFCWinApp;
|
||||||
|
Reference in New Issue
Block a user