Redaguoti

Bendrinti naudojant


Setting the Dialog Box's Background Color

You can set the background color of your dialog boxes by handling WM_CTLCOLOR messages for the dialog box window. The color you set is used for only the specified dialog box.

For example, the following code fragment sets the background color of the dialog box to dark grey. The OnCtlColor member function is called whenever the dialog box is redrawn:

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    return (HBRUSH)GetStockObject(DKGRAY_BRUSH);
}

For the previous code fragment to work:

  • add virtual HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); to the protected: section of the class definition for your dialog.
  • add the following to the class definition for your dialog, and change CMyDialog to the name of your dialog class:
BEGIN_MESSAGE_MAP(CMyDialog, CDialogEx)
    ON_WM_CTLCOLOR()
END_MESSAGE_MAP()

See also

Working with Dialog Boxes in MFC
Handling Windows Messages in Your Dialog Box