S.l.e!ep.¢%

像打了激速一样,以四倍的速度运转,开心的工作
简单、开放、平等的公司文化;尊重个性、自由与个人价值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Avoid Other Program Send WM_QUIT to Close the Window

Posted on 2009-12-29 15:36 S.l.e!ep.¢% 阅读(335) 评论(0)  编辑 收藏 引用 所属分类: VC
Avoid 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;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理