background color

i have a modaless dialog as a child window, how do i change the color of the parent window to green instead of white?
[117 byte] By [shaulch] at [2007-11-17 22:39:52]
# 1 Re: background color
you could try overwriting WM_ERASEBKGND

something like

BOOL CTestView::OnEraseBkgnd(CDC* pDC)
{
CRect rcClient;
GetClientRect( &rcClient );
pDC->FillRect(rcClient, &CBrush(RGB(0,128,0)));
return TRUE;
}

hope this helps

Steven Roelants
s. roelants at 2007-11-10 8:41:39 >
# 2 Re: background color
CGreenDialog::CGreenDialog(CWnd* pParent /*=NULL*/)
: CDialog(CGreenDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CGreenDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
greenBrush.CreateSolidBrush(RGB(0,255,0));
}

BEGIN_MESSAGE_MAP(CGreenDialog, CDialog)
//{{AFX_MSG_MAP(CGreenDialog)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

HBRUSH CGreenDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(CTLCOLOR_DLG == nCtlColor)
return greenBrush;
return hbr;
}
Brandon Parker at 2007-11-10 8:42:41 >
# 3 Re: background color
still pepople uses MFC for such small task :(
here is a better one

HBRUSH hbrushWindow = CreateSolidBrush(RGB(70,151,232));

case WM_CTLCOLORDLG: // coloring the window
{
return (LONG)hbrushWindow; // with the handle we set (color)
}
Bengi at 2007-11-10 8:43:46 >
# 4 Re: background color
thank u very much
shaulch at 2007-11-10 8:44:52 >
# 5 Re: background color
thanks bengi, really great and easy.
juergen
juergen at 2007-11-10 8:45:51 >