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:
Vadim Zeitlin
2017-12-11 23:07:33 +01:00
parent 636219bd35
commit 44c31d2700

View File

@@ -122,6 +122,11 @@ protected:
// running.
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
// application when this window is closed, as OnRun(), which does this
// by default, won't be called when using MFC main message loop.
@@ -129,6 +134,15 @@ protected:
return TRUE;
}
private:
void OnMainWindowDestroyed(wxWindowDestroyEvent& event)
{
event.Skip();
delete m_pMainWnd;
m_pMainWnd = NULL;
}
};
typedef wxMFCApp<CWinApp> wxMFCWinApp;