Avoid Other Program Send WM_QUIT to Close the Window
Posted on 2009-12-29 15:36 S.l.e!ep.¢% 閱讀(346) 評論(0) 編輯 收藏 引用 所屬分類: VCAvoid Other Program Send WM_QUIT to Close the Window, 研究了下 MFC 的代碼,發現進入 dlg.DoModal(); 后, 就會調用一個 PumpMessage 的東東, 所以解決方法很簡單, 重載 PumpMessage 即可
BOOL?CXXXApp::PumpMessage()


{
????ASSERT_VALID(this);
????
????if?(!::GetMessage(&m_msgCur,?NULL,?NULL,?NULL))

????
{
#ifdef?_DEBUG
????????if(m_msgCur.message?==?WM_QUIT)

????????
{
????????????TRACE0("CWinThread::PumpMessage?-?Received?WM_QUIT.\n");
????????????TRACE1("m_msgCur.hwnd=0x%x.\n",?m_msgCur.hwnd);

????????????return?TRUE;
????????}
????????m_nDisablePumpCount++;?//?application?must?die
????????//?Note:?prevents?calling?message?loop?things?in?'ExitInstance'
????????//?will?never?be?decremented
#endif
????????return?FALSE;
????}
????
#ifdef?_DEBUG
????if?(m_nDisablePumpCount?!=?0)

????
{
????????TRACE0("Error:?CWinThread::PumpMessage?called?when?not?permitted.\n");
????????ASSERT(FALSE);
????}
#endif
????
//?#ifdef?_DEBUG
//?????if?(afxTraceFlags?&?traceAppMsg)
//?????????_AfxTraceMsg(_T("PumpMessage"),?&m_msgCur);
//?#endif
????
????//?process?this?message
????#define?WM_KICKIDLE?0x036A?
????if?(m_msgCur.message?!=?WM_KICKIDLE?&&?!PreTranslateMessage(&m_msgCur))

????
{
????????::TranslateMessage(&m_msgCur);
????????::DispatchMessage(&m_msgCur);
????}
????return?TRUE;
}




















































