对话框窗口不刷新,不进入OnPaint(不进WM_PAINT)

来源:互联网 发布:热血屠龙翅膀进阶数据 编辑:程序博客网 时间:2024/06/07 09:35

MFC对话框程序,不知道改了什么对话框总是不刷新,后来用spy++查看,能看到窗口。
首先考虑的是,不小心加了layeredout属性,后来查看没有。
再次考虑到是不是wm_paint消息被过滤了,在PreTranslateMessage里面下断点发现是可以收到WM_PAINT消息的,后来调试跟进,发现

代码堆栈
PreTranslateMessage最后返回TRUE导致没有进入if代码块,当然不会刷新了。所以应该为如下代码:

BOOL CMFCTryDemoDlg::PreTranslateMessage(MSG* pMsg){    // TODO: 在此添加专用代码和/或调用基类    if(pMsg->message == WM_USER+100)    {    }    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.

原创粉丝点击