1.
重载OnCtlColor (CDC* pDC, CWnd* pWnd, UINT nCtlColor),即WM_CTLCOLOR消息。
---- ①在CExampleDlgDlg的头文件中,添加一CBrush的成员变量:
class CExampleDlgDlg : public CDialog
{...
protected:
CBrush m_brush;
...
};
---- ②在OnInitDialog()函数中添加如下代码:
BOOL CExampleDlgDlg::OnInitDialog()
{
...
// TODO: Add extra initialization here
m_brush.CreateSolidBrush(RGB(0, 255, 0)); // 生成一绿色刷子
...
}
---- ③利用ClassWizard重载OnCtlColor(…),即WM_CTLCOLOR消息:
HBRUSH CExampleDlgDlg::OnCtlColor
(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/*
** 这里不必编写任何代码!
**下行代码要注释掉
** HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
*/
return m_brush; //返加绿色刷子
}
2.
修改对话框的OnPaint,在else中添加如下代码
CPaintDC dc(this);
CRect rect;
GetClientRect(rect);
dc.FillSolidRect(rect, RGB(0,0,0));
CDialog::OnPaint();
3.
在对话框的应用类(App)的.cpp的Initinstance()中加入代码:
//加在int nResponse=dlg.DoModal();
前一个RGB设置背景色,第二个设置字体颜色
SetDialogBkColor(RGB(0,0,255),RGB(0,255,0));
4.
1.在对话框类中添加成员变量:
public:
CBrush m_brushBlue;
2.在对话框类的OnInitDialog()中添加代码:
m_brushBlue.CreateSolidBrush(RGB(0,0,255));
3.用ClassWizard在对话框类中添加成员函数OnCtlCollor(),并在其中添加代码:
if(nCtlColor==CTLCOLOR_DLG)
return m_brushBlue;
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mfreesky/archive/2007/08/27/1760222.aspx