OnEraseBkand()当窗口背景必须被擦除时被调用,如当你的窗口大小改变时,或者其他情况.调用该函数的结果是为了准备有效的重画区域,该函数返回0,表示不擦除背景,非0表示需要擦除背景.

解决方案 »

  1.   


    窗口收到ERASEBKGND消息的时候,具体的到底是什么时候触发消息?我也把不准,不过更新界面函数都提供了是否擦除背景的选项.
    我个人分析认为:
    (1) 界面无效后,系统触发.
    (2) 象invalidate() updatewindow()等之类函数触发
      

  2.   

    你可以在WM_ERASEBKGND中加入下面的代码
    PostMessage(WM_PAINT);
      

  3.   

    WM_ERASEBKGND
    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
      

  4.   

    OnEraseBkand()当窗口背景必须被擦除时被调用,如当你的窗口大小改变时,或者其他情况,具体看WM_ERASEBKGND。
        我想设置该消息的目的是为了解决对话框重画的问题。由于对话框包含了很多控件,直接使用wm_paint重画客户区,很可能出现显示的混乱,所以在CDialog类中,wm_paint无法实现及时的窗体更新,例如实现非系统色背景。
        所以引入WM_ERASEBKGND更新对话框背景。
      

  5.   

    在WM_PAINT之前,有WM_ERASEBKGND来先进行处理!