MFC dialog background colour change

Associate
Joined
26 Jan 2005
Posts
1,796
Location
Cheltenham, UK
Hi Guys,

I need to change the colour of a dialog background the app is being developed in visual studio 2005 using vc2005++ and MFC. I'm completely stumped on how to do this (I have had zero MFC teaching) so any help would be massively appreciated.
 
I had to figure this out in pure Win32 API a while ago (I was bored and wanted to write a small exe), and kept finding ways to do it in MFC annoyingly :p.

Code:
BOOL CMyDialog::OnEraseBkgnd(CDC *pDC)
{
  CRect rect;
  GetClientRect(&rect);
  CBrush myBrush(RGB(255,0,0)); // Solid RED for instance
  CBrush *pOld = pDC->SelectObject(&myBrush);
  BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
  pDC->SelectObject(pOld); // Have to restore old brush
  return bRes;
}
http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_21674646.html

Maybe?

I'll post up the API way if not.

Also:
http://msdn.microsoft.com/en-us/library/4d9az9wf(VS.80).aspx
http://www.codeguru.com/cpp/w-d/dislog/miscellaneous/article.php/c1909
 
Hey dude, sorry for the unbelievably slow response. It was a long weekend a friend from Uni came over for the weekend but we're not best friends and he was making himself a little too much at home which meant I couldn't really relax when in my flat (although fine when out clubbing). Anyway thank you very much for the solution! I have to admit I did get some help from a colleague but it's all working now! :D
 
Back
Top Bottom