1.头文件里定义一个画刷:
CBrush m_brushColor;
2.在OnInitDialog()初始化时创建画刷,并设置实际的颜色:
m_brushColor.CreateSolidBrush ( RGB ( 100, 100, 255 ));//初始化颜色画刷
3.通过类向导添加afx_msg HBRUSH OnCtlColor()函数,并返回颜色刷子:
HBRUSH CxxxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor ==CTLCOLOR_DLG)
return m_brushColor; //返回颜色刷子
}