virtual void OnFinalMessage(HWND ){...}
函數(shù)內(nèi)加一句
delete this;
然后就返回了. 但是氣人的是, 每次當(dāng)我們返回后, 總有一個(gè)地方斷言失敗,
ATLASSERT(pThis->m_pCurrentMsg == &msg);
Google 了許久, 沒(méi)有滿(mǎn)意的解決方案, 包括微軟的方案
http://support.microsoft.com/kb/202110
也不好, 自己想盡辦法還是 "山重水復(fù)疑無(wú)路", 后來(lái)突然靈光突現(xiàn), 徹底解決, 就一個(gè)函數(shù)調(diào)用而已: IsWindow(...). 現(xiàn)在, 終極解決方案是這樣的:
搜索 atlwin.h 文件內(nèi)的 "ATLASSERT(pThis->m_pCurrentMsg == &msg);" 字符串 (在文件內(nèi)有 3 處), 將其原始內(nèi)容
LRESULT lRes;
BOOL bRet = pThis->ProcessWindowMessage(pThis->m_hWnd, uMsg, wParam, lParam, lRes, 0);
// restore saved value for the current message
ATLASSERT(pThis->m_pCurrentMsg == &msg);
pThis->m_pCurrentMsg = pOldMsg;
改成BOOL bRet = pThis->ProcessWindowMessage(pThis->m_hWnd, uMsg, wParam, lParam, lRes, 0);
// restore saved value for the current message
ATLASSERT(pThis->m_pCurrentMsg == &msg);
pThis->m_pCurrentMsg = pOldMsg;
LRESULT lRes;
BOOL bRet = pThis->ProcessWindowMessage(pThis->m_hWnd, uMsg, wParam, lParam, lRes, 0);
if(FALSE == ::IsWindow(pThis->m_hWnd)) {
return lRes; // 在 CDialogImplBaseT 類(lèi)里是 return FALSE; 特此說(shuō)明
}
// restore saved value for the current message
ATLASSERT(pThis->m_pCurrentMsg == &msg);
pThis->m_pCurrentMsg = pOldMsg;
其中紅色的代碼為我們的修正代碼. 萬(wàn)事大吉. 再也不會(huì)出現(xiàn)斷言失敗了. BOOL bRet = pThis->ProcessWindowMessage(pThis->m_hWnd, uMsg, wParam, lParam, lRes, 0);
if(FALSE == ::IsWindow(pThis->m_hWnd)) {
return lRes; // 在 CDialogImplBaseT 類(lèi)里是 return FALSE; 特此說(shuō)明
}
// restore saved value for the current message
ATLASSERT(pThis->m_pCurrentMsg == &msg);
pThis->m_pCurrentMsg = pOldMsg;
道理是這樣的: 如果 pThis 對(duì)象被刪除了的話, 那么 pThis 本身和其成員變量 m_hWnd 都將是一個(gè)無(wú)效值, 那么后續(xù)的操作將毫無(wú)意義. 因此直接返回, 不用廢話.
真是簡(jiǎn)單的思路直指問(wèn)題的核心啊.