OnEraseBkand()当窗口背景必须被擦除时被调用,如当你的窗口大小改变时,或者其他情况.调用该函数的结果是为了准备有效的重画区域,该函数返回0,表示不擦除背景,非0表示需要擦除背景.
解决方案 »
- WTL程序中如何打开并按行读取文件?
- 同一个单文档文件,有两个对话框在初始化中调用同一个access数据库,运行报错:unknown error ox800A0E7D
- 关于 sprintf 函数得到错误结果问题的一些调试现象,网各位大侠帮忙分析一下
- 新手做的计算器 有问题待解决
- 貌似简单的问题:在编辑框的菜单中添加条目并能响应!
- 关于Edit控件的问题
- 为什么我#include <wininet.h>就会编译错误?
- 问一个关于Direct8编程的问题!
- Windows 2000的文件系统是不是有问题
- 如何禁止菜单或工具条中的某一项??
- 怎样实现运行的程序不显示在进程列表里??
- 有谁在w2k下配置组件服务和web服务分离,高分答谢!!!
窗口收到ERASEBKGND消息的时候,具体的到底是什么时候触发消息?我也把不准,不过更新界面函数都提供了是否擦除背景的选项.
我个人分析认为:
(1) 界面无效后,系统触发.
(2) 象invalidate() updatewindow()等之类函数触发
PostMessage(WM_PAINT);
The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting. A window receives this message through its WindowProc function. LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_ERASEBKGND
WPARAM wParam, // handle to device context (HDC)
LPARAM lParam // not used
);
Parameters
wParam
Handle to the device context.
lParam
This parameter is not used.
Return Values
An application should return nonzero if it erases the background; otherwise, it should return zero. Res
The DefWindowProc function erases the background by using the class background brush specified by the hbrBackground member of the WNDCLASS structure. If hbrBackground is NULL, the application should process the WM_ERASEBKGND message and erase the background. An application should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If the application returns zero, the window will remain ed for erasing. (Typically, this indicates that the fErase member of the PAINTSTRUCT structure will be TRUE.) --------------------------------------
CWnd::OnEraseBkgnd
afx_msg BOOL OnEraseBkgnd( CDC* pDC );Return ValueNonzero if it erases the background; otherwise 0.ParameterspDCSpecifies the device-context object.ResThe framework calls this member function when the CWnd object background needs erasing (for example, when resized). It is called to prepare an invalidated region for painting.The default implementation erases the background using the window class background brush specified by the hbrBackground member of the window class structure. If the hbrBackground member is NULL, your overridden version of OnEraseBkgnd should erase the background color. Your version should also align the origin of the intended brush with the CWnd coordinates by first callingUnrealizeObject for the brush, and then selecting the brush.An overridden OnEraseBkgnd should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If it returns 0, the window will remain ed as needing to be erased. (Typically, this means that the fErase member of the PAINTSTRUCT structure will be TRUE.) Windows assumes the background is computed with the MM_TEXT mapping mode. If the device context is using any other mapping mode, the area erased may not be within the visible part of the client area.Note This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
窗口重画背景时候调用,具体看WM_ERASEBKGND
我想设置该消息的目的是为了解决对话框重画的问题。由于对话框包含了很多控件,直接使用wm_paint重画客户区,很可能出现显示的混乱,所以在CDialog类中,wm_paint无法实现及时的窗体更新,例如实现非系统色背景。
所以引入WM_ERASEBKGND更新对话框背景。