Skip to main content

MFC: Fill Client area with a desired color

· One min read

MFC Tip: To fill the Background of the client area with a desired color keeping the text in the client area unchanged

BOOL CMySDIView::OnEraseBkgnd(CDC\* pDC)
{
CRect r;
//GetClientRect gets the width & height of the client area of
//the window
GetClientRect(&r);
CBrush br(RGB(255,250,100));
pDC->SelectObject(br);
pDC->FillRect(r,&br);

return TRUE;
}