Saturday, May 19, 2012

Changing the background color of a dialog

November 1, 2009 by · Leave a Comment 

If you want to change the background color of your dialog box, it is a very simple.

In your CTestDlg header file, declare a member variable from CBrush:

class CTestDlg : public CDialog{…protected: CBrush m_brush;…};

Then, add this line in the OnInitDialog function:

BOOL CTestDlg::OnInitDialog(){ … m_brush.CreateSolidBrush(RGB(255, 255, 255));

// color white brush …

}

Finally do this on the ID_CTLCOLOR handle:

BEGIN_MESSAGE_MAP(CDesktopToSWFDlg, CTrayDialog) ON_WM_CTLCOLOR()END_MESSAGE_MAP()

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor){

/*** No need to do this!****

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

*//*** Return the white brush.*/

return m_brush;}

Hope it could help any fellow programmer.

Top Blogs

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

*