Hi,
There is no direct method to set the background color of a dialog box.
However, you can do by the following method,
Create a CBrush member variable for the CDialog derived class
CBrush m_pbkBrush;
in OnInitDialog create the brush with a suitable color
m_pbkBrush.CreateSolidBrush(RGB(255,0,0));
add WM_CTLCOLOR message map and make the following changes in the message
handler function
HBRUSH CMFCTabDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr;
if (nCtlColor == CTLCOLOR_DLG)
hbr = (HBRUSH)m_pbkBrush.GetSafeHandle();
else
hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}
and whereever you want the background to be changed like your button click,
delete the old brush object and recreate with the new color and call
Invalidate()
m_pbkBrush.DeleteObject();
m_pbkBrush.CreateSolidBrush(RGB(0,255,0));
Invalidate();
------------------------------
Ashok K Kumar
> i can change the dialog background color by calling the
> function----SetDialogBkColor(RGB(0,0,255),RGB(255,0,0))-----in the function
> InitInstance(), but i want to change the background color only by clicking a
> button on the dialog. what should i do? thanks!!