首先在头文件里定义一个背景色的宏:
#define DLG_BACKGROUND RGB(220, 210, 201)
然后在CPP文件里添加映射二个函数:
BEGIN_MESSAGE_MAP(CDb9EWaveProDlg, CDialogEx) ON_WM_CTLCOLOR()//字体颜色 ON_WM_ERASEBKGND() //背景色 END_MESSAGE_MAP()
重载函数定义例如以下:
HBRUSH CxxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_EDIT || nCtlColor == CTLCOLOR_LISTBOX) { pDC->SetBkColor(RGB(255, 255, 255)); return hbr; } else { HBRUSH hBrush = CreateSolidBrush(DLG_BACKGROUND); //创建背景刷; pDC->SetBkMode(TRANSPARENT); return hBrush; } } BOOL CxxDlg::OnEraseBkgnd(CDC* pDC) { CBrush back(DLG_BACKGROUND); CBrush* pold=pDC->SelectObject(&back); CRect rect; pDC->GetClipBox (&rect); pDC->PatBlt (rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY); pDC->SelectObject(pold); return TRUE; }
OK, Down.