Changing background color of View

Using Class Wizard, write a handler for WM_ERASEBKGND message and write this code.

BOOL CColorviewView::OnEraseBkgnd(CDC* pDC) 

{

// TODO: Add your message handler code here and/or call default

CRect rect;

/* GetClipBox Retrieves the dimensions of the view area and copies to the buffer pointed to by rect. */

pDC->GetClipBox( &rect);

/* Fill view area with blue color. COLORREF is based on RGB color and hexa code is 0x00bbggrr */

COLORREF fillColor = 0x00bb0000 ; // blue color

/* Create the bursh and select into DC */

CBrush brush ( fillColor );

CBrush* pOldBrush = pDC->SelectObject( &brush );

/* PatBlt Creates a bit pattern on the device. See MDSN for more details */

pDC->PatBlt( rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY );

pDC->SelectObject( pOldBrush ) ; 

return TRUE;

}