天天看點

對話框視窗不重新整理,不進入OnPaint(不進WM_PAINT)

MFC對話框程式,不知道改了什麼對話框總是不重新整理,後來用spy++檢視,能看到視窗。

首先考慮的是,不小心加了layeredout屬性,後來檢視沒有。

再次考慮到是不是wm_paint消息被過濾了,在PreTranslateMessage裡面下斷點發現是可以收到WM_PAINT消息的,後來調試跟進,發現

對話框視窗不重新整理,不進入OnPaint(不進WM_PAINT)

PreTranslateMessage最後傳回TRUE導緻沒有進入if代碼塊,當然不會重新整理了。是以應該為如下代碼:

BOOL CMFCTryDemoDlg::PreTranslateMessage(MSG* pMsg)
{
    // TODO: 在此添加專用代碼和/或調用基類
    if(pMsg->message == WM_USER+)
    {

    }
    else
        return CDialog::PreTranslateMessage(pMsg);
}
           

=================================================

倒是不用看msdn,不過還是看了下:

要檢視本文的譯文,請勾選“翻譯”複選框。也可将滑鼠指針移到文本上,在彈出視窗中顯示譯文。

翻譯 英語

CWnd::PreTranslateMessage

其他版本

Used by class CWinApp to translate window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions.

文法

virtual BOOL PreTranslateMessage(
           

MSG* pMsg

);

參數

pMsg

Points to a MSG structure that contains the message to process.

傳回值

Nonzero if the message was translated and should not be dispatched; 0 if the message was not translated and should be dispatched.