drgon的消息處理

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">dragon裏隨處可見mfc相似的消息處理宏,展開后里邊有個processmessage函數,那麼,自然這個就是消息處理的函數了,那麼,這個函數又由誰調用</span>

	BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0) \
	{ \
		BOOL bOldMsgHandled = m_bMsgHandled; \
		BOOL bRet = _ProcessWindowMessage(hWnd, uMsg, wParam, lParam, lResult, dwMsgMapID); \
		m_bMsgHandled = bOldMsgHandled; \
		return bRet; \
	} \

再往上查找

//
//	[private] LRESULT WndProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
//
//	窗口被子類化過之後的窗口過程
//
LRESULT	WindowBase::WndProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	LRESULT lRes;
	UIMSG*  pOldMsg = m_pCurMsg;
	BOOL bHandled = this->ProcessWindowMessage(m_hWnd, uMsg, wParam, lParam, lRes, 0);  // 調用BEGIN_MSG_MAP消息映射列表
	if (bHandled)
	{
		return WndProc_GetRetValue(uMsg, wParam, lParam, bHandled, lRes);
	}
    
    // 直接發給當前窗口處理
    UIMSG  msg;
	msg.message = uMsg;
	msg.pMsgTo = this->GetIMessage();
	msg.wParam = wParam;
	msg.lParam = lParam;

	// 如果這個消息被處理過了,直接返回,不用再調用舊的窗口過程了
	//if (static_cast<IMessage*>(this)->ProcessMessage(&msg, 0))
    UISendMessage(&msg);
    lRes = WndProc_GetRetValue(uMsg, wParam, lParam,  msg.bHandled, msg.lRet);

	if (uMsg == WM_NCDESTROY)
	{
		// 注:爲什麼不在這裏直接調用OnFinalMessage,卻還要再加一個狀態位?
		// 因爲WM_NCDESTROY函數由DestroyWindow api觸發,而DestroyWindow api
		// 可能位於任何一個當前窗口的消息響應中,因此當pOldMsg==NULL時,即表示
		// 沒有消息嵌套了,在檢查一次WINDOW_STYLE_DESTROYED標誌即可。
		this->ModifyStyle(WINDOW_STYLE_DESTROYED, 0, 0);
	}
	if (m_nStyle & WINDOW_STYLE_DESTROYED && pOldMsg == NULL)
	{
		this->ModifyStyle(0, WINDOW_STYLE_DESTROYED, 0);
	}

	return lRes;
}
再往上找

//
//	[static] LRESULT CALLBACK ThunkWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
//
//	被ATL的thunk替換過的窗口過程
//
//	Parameter:
//		hwnd
//			[in]	這裏由於被替換過了,這裏的hwnd是this指針
//
//		uMsg,wParam,lParam
//			[in]	消息信息
//
LRESULT  WindowBase::ThunkWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	WindowBase* pThis = (WindowBase*)hwnd;
	LRESULT lRet = 0;

	if (FALSE == pThis->PreTranslateMessage(uMsg, wParam, lParam, &lRet))
		lRet = pThis->WndProc( uMsg, wParam, lParam );

	return lRet;
}
哦哦,這裏看到這個名稱就明白了,大致也就到了替換的窗口過程,關於thunk技術在另外的文章中介結,到此,消息處理就大致明白了,這裏沒有仔累的查看細節。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章