Changing the Default Background Color in an SDI Application


Application Security Testing: An Integral Part of DevOps

Environment: SDI MFC projects

SDI projects created using MFC come with a default white background color. This sample code implements any color the programmer desires after the creation of an SDI framework using the MFC wizard for project creation.

  1. Ctrl+W pops up the MFC classwizard property sheet.
  2. Select the Message Maps tab.
  3. From the drop-down list box under the Class Name static control, select the CxxxView option (xxx = Your project's name; for example, CNnoyeView).
  4. Make sure CxxxView is also selected in the Object ID's list box.
  5. Select the WM_ERASEBKGND option in the Messages list box.
  6. Click the Add Function button. The Class Wizard adds the "OnEraseBkgnd" member function.
  7. Click the Edit Code button. Add the following code before the return CView::OnEraseBkgnd(pDC) statement.
CBrush brNew(RGB(0,0,255));  //Creates a blue brush
CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&brNew);

CRect rc;
pDC->GetClipBox(rc); // Gets the co-ordinates of the client
                     // area to repaint.
                     // Repaints client area with current brush.

return TRUE;    // Prevents the execution of return
                // CView::OnEraseBkgnd(pDC) statement

You can choose any desired color background by adjusting the values of Red, Green, and Blue in RGB(0,0,255); for example, RGB(0,0,0)=Black. You can also use bitmaps instead of brushes as the background color with simple adjustments. Guess that's it for now, folks! Have to get back to work.


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.