BOOL CWinThread::PumpMessage(){ return AfxInternalPumpMessage();}
BOOL AFXAPI AfxInternalPumpMessage(){ _AFX_THREAD_STATE *pState = AfxGetThreadState();
if (!::GetMessage(&(pState->m_msgCur), NULL, NULL, NULL)) {#ifdef _DEBUG TRACE(traceAppMsg, 1, _T("CWinThread::PumpMessage - Received WM_QUIT.\n")); pState->m_nDisablePumpCount++; // application must die#endif // Note: prevents calling message loop things in 'ExitInstance' // will never be decremented return FALSE; }
#ifdef _DEBUG if (pState->m_nDisablePumpCount != 0) { TRACE(traceAppMsg, 0, _T("Error: CWinThread::PumpMessage called when not permitted.\n")); ASSERT(FALSE); }#endif
#ifdef _DEBUG _AfxTraceMsg(_T("PumpMessage"), &(pState->m_msgCur));#endif
// process this message
if (pState->m_msgCur.message != WM_KICKIDLE && !AfxPreTranslateMessage(&(pState->m_msgCur))) { ::TranslateMessage(&(pState->m_msgCur)); ::DispatchMessage(&(pState->m_msgCur)); } return TRUE;}BOOL __cdecl AfxPreTranslateMessage(MSG* pMsg){ CWinThread *pThread = AfxGetThread(); if( pThread ) return pThread->PreTranslateMessage( pMsg ); else return AfxInternalPreTranslateMessage( pMsg );}BOOL CWinThread::PreTranslateMessage(MSG* pMsg){ ASSERT_VALID(this); return AfxInternalPreTranslateMessage( pMsg );}BOOL AfxInternalPreTranslateMessage(MSG* pMsg){// ASSERT_VALID(this);
CWinThread *pThread = AfxGetThread(); if( pThread ) { // if this is a thread-message, short-circuit this function if (pMsg->hwnd == NULL && pThread->DispatchThreadMessageEx(pMsg)) return TRUE; }
// walk from target to main window CWnd* pMainWnd = AfxGetMainWnd(); if (CWnd::WalkPreTranslateTree(pMainWnd->GetSafeHwnd(), pMsg)) return TRUE;
// in case of modeless dialogs, last chance route through main // window's accelerator table if (pMainWnd != NULL) { CWnd* pWnd = CWnd::FromHandle(pMsg->hwnd); if (pWnd->GetTopLevelParent() != pMainWnd) return pMainWnd->PreTranslateMessage(pMsg); }
return FALSE; // no special processing}
BOOL PASCAL CWnd::WalkPreTranslateTree(HWND hWndStop, MSG* pMsg){ ASSERT(hWndStop == NULL || ::IsWindow(hWndStop)); ASSERT(pMsg != NULL);
// walk from the target window up to the hWndStop window checking // if any window wants to translate this message
for (HWND hWnd = pMsg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd)) { CWnd* pWnd = CWnd::FromHandlePermanent(hWnd); if (pWnd != NULL) { // target window is a C++ window if (pWnd->PreTranslateMessage(pMsg)) return TRUE; // trapped by target window (eg: accelerato
rs) }
// got to hWndStop window without interest if (hWnd == hWndStop) break; } return FALSE; // no special processing}