代码放在对话框的onpaint中,作用是利用桌面的背景做对话框的背景,请大家解释一下代码!!
PaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);if (IsIconic())
{// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
HDC hdc = dc.GetSafeHdc() ;
::SetBkColor( hdc , RGB(255, 0, 100));
CDialog::OnPaint();
}

解决方案 »

  1.   

    把本该画到desktop窗口,也就是当前窗口的背景的内容画到当前窗口之内。
      

  2.   

    好像背景颜色是个死的,关键代码为SetBkColor( hdc , RGB(255, 0, 100))
      

  3.   

    我试了试sdk的程序也有相同的情况,他不是mfc的问题
    你读读这段话~~~  
      Platform SDK: Windows User Interface 
    WM_ICONERASEBKGND
    Windows NT 3.51 and earlier: The WM_ICONERASEBKGND message is sent to a minimized window when the background of the icon must be filled before painting the icon. A window receives this message only if a class icon is defined for the window; otherwise, WM_ERASEBKGND is sent. This message is not sent by newer versions of Windows.A window receives this message through its WindowProc function. LRESULT CALLBACK WindowProc(
      HWND hwnd,       // handle to window
      UINT uMsg,       // WM_ICONERASEBKGND
      WPARAM wParam,   // handle to device context (HDC)
      LPARAM lParam    // not used
    );
    Parameters
    wParam 
    Handle to the device context of the icon. 
    lParam 
    This parameter is not used. 
    Return Values
    An application should return nonzero if it processes this message. Res
    Windows NT 3.51 and earlier: The DefWindowProc function fills the icon background with the class background brush of the parent window. On newer versions of Windows, the DefWindowProc function ignores the message.Requirements 
      Windows NT/2000/XP: Included in Windows NT 3.1 and later.
      Windows 95/98/Me: Included in Windows 95 and later.
      Header: Declared in Winuser.h; include Windows.h.See Also
    Icons Overview, Icon Messages, DefWindowProc, WM_ERASEBKGND Platform SDK Release: November 2001  What did you think of this topic?
    Let us know.  Order a Platform SDK CD Online
    (U.S/Canada)   (International)  Requirements 
      Windows NT/2000/XP: Included in Windows NT 3.1 and later.
      Windows 95/98/Me: Included in Windows 95 and later.
      Header: Declared in Winuser.h; include Windows.h.
    See Also
    Icons Overview, Icon Messages, DefWindowProc, WM_ERASEBKGND 
    ------------------
    就是说defwindowproc会自动让系统重画,实际上就是取那个hdc的裁剪区域,让系统desktop窗口专门重画那一块