Article ID: 103786
Article Last Modified on 11/21/2006
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:
129471 How To Subclass the MDICLIENT by Using MFC
if (!m_wndNewClient.SubclassWindow(m_hWndMDIClient))
{
TRACE("Failed to subclass MDI client window\n");
return -1; // fail to create
}
m_hWndMDIClient is the member variable of CMDIFrameWnd that
contains the handle to the MDI client window. Also, replace
"m_wndNewClient" with the data member that you created in step 2.
WNDPROC* CNewClientWnd::GetSuperWndProcAddr()
{
static WNDPROC NEAR pfnSuper = NULL;
return &pfnSuper;
}
NOTE: Replace "CNewClientWnd" above with the name of your class.
subclass and sample and mfc
changing and background and color and MFC
Keywords: kbhowto KB103786