给类CXXFormView添加一个CBrush类的成员变量m_brush
然后在其构造函数中加m_brush.CreateSolidBrush(RGB(255,255,255));
如我的CXXFormView类
CPackInterView::CPackInterView()
: CFormView(CPackInterView::IDD)
{
//{{AFX_DATA_INIT(CPackInterView)
//}}AFX_DATA_INIT
m_brush.CreateSolidBrush(RGB(255,255,255));//设为白色
}
接着映射一个WM_CTLCOLOR消息,在ClassWizard中添加.在OnCtlColor中如下设置即可
HBRUSH CPackInterView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_DLG)
return (HBRUSH)m_brush.GetSafeHandle();
// TODO: Return a different brush if the default is not desired
return hbr;
}