change background color of childview dynamically

I'm new to MFC and I'm trying to dynamically change the background color of a childview.  I can set a color in the preCreateWindow(), but I don't know how to change the color dynamically.  
deetz623Asked:
Who is Participating?
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
Trap the WM_ERASEBKGND message and create a handler for it with the wizard.
Then in the function fill the background with the colour you want and return TRUE from the function,

eg.
BOOL CXyzView::OnEraseBkgnd(CDC* pDC)
{
      CRect rect;
      GetClientRect(&rect);
      pDC->FillSolidRect(&rect, RGB(255, 0,0,));
      
      //return CView::OnEraseBkgnd(pDC);
      return TRUE;
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.