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.