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.
BEGIN_MESSAGE_MAP(MyDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_WM_ERASEBKGND()END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(MyDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
class MyDlg : public CDialog{// Constructionpublic: MyDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data enum { IDD = IDD_MY_DIALOG };protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support// Implementationprotected: HICON m_hIcon; // Generated message map functions virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP()public: afx_msg BOOL OnEraseBkgnd(CDC* pDC);};
Write the OnEraseBkgnd() function definition in the CPP file:
BOOL MyDlg::OnEraseBkgnd(CDC* pDC){ CRect rect; GetClientRect(&rect); CBrush myBrush(RGB(255, 255, 255)); // dialog background color CBrush *pOld = pDC->SelectObject(&myBrush); BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY); pDC->SelectObject(pOld); // restore old brush return bRes; // CDialog::OnEraseBkgnd(pDC);}
That should do.