| HOWTO: Change Window Background Color with Foundation ClassesLast reviewed: May 28, 1997Article ID: Q103786 | 
| The information in this article applies to: 
 
 SUMMARYTo change the background color for a CView, CFrameWnd, or CWnd object, process the WM_ERASEBKGND message. The sample code below demonstrates how to do this. 
 MORE INFORMATION
 Sample Code
    BOOL CSampleView::OnEraseBkgnd(CDC* pDC)
   {
      // Set brush to desired background color
      CBrush backBrush(RGB(255, 128, 128));
      // Save old brush
      CBrush* pOldBrush = pDC->SelectObject(&backBrush);
      CRect rect;
      pDC->GetClipBox(&rect);     // Erase the area needed
      pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
          PATCOPY);
      pDC->SelectObject(pOldBrush);
      return TRUE;
   }
To change the background color for a CMDIFrameWnd, you must subclass the
multiple document interface (MDI) client window (window in the client area
of CMDIFrameWnd) and process the WM_ERASEBKGND message. For more
information about the MDI client window in an MDI application, see chapter
18 in "Programming Windows 3.1 - Third Edition" by Charles Petzold. For an
example that shows how to subclass the MDICLIENT window, please see the
article in the Microsoft Knowledge Base:
 ARTICLE-ID: Q129471 TITLE : HOWTO: Subclass the MDICLIENT by Using MFCTo change the background color of an MDI client window (client area of a CMDIFrameWnd), perform the following steps using an AppWizard-generated application: 
 For more information on changing the background color of a dialog box by processing the WM_CTLCOLOR message, please query on the following words in the Microsoft Knowledge Base: 
 changing and background and color and MFC | 
| Keywords : MfcUI kbfasttip kbhowto 
 © 1998 Microsoft Corporation. All rights reserved. Terms of Use. |