all groups > visual c libraries > november 2004 >
You're in the

visual c libraries

group:

how to change the dialog background color by clicking a button?


how to change the dialog background color by clicking a button? Mark
11/28/2004 4:23:02 AM
visual c libraries:
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
Re: how to change the dialog background color by clicking a button? Ashok K Kumar
11/30/2004 10:51:06 PM
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


[quoted text, click to view]

AddThis Social Bookmark Button