重载 OnEraseBkgnd
然后看看这个
HBRUSH CMyView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
switch( nCtlColor )
{
case CTLCOLOR_EDIT:
if( pWnd->m_hWnd==m_editContent.m_hWnd )
{
pDC->SetBkColor(RGB(0,100,100));
pDC->SetTextColor(RGB(0,255,250 ));
}
break;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
然后看看这个
HBRUSH CMyView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
switch( nCtlColor )
{
case CTLCOLOR_EDIT:
if( pWnd->m_hWnd==m_editContent.m_hWnd )
{
pDC->SetBkColor(RGB(0,100,100));
pDC->SetTextColor(RGB(0,255,250 ));
}
break;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
OnEraseBkgnd ---------- WM_ERASEBKGND
CRect rect;
GetClientRect(&rect);
pDC->FillSolidRect(&rect,RGB(0,100,0));
return TRUE;
在Instance函数里加入:
//在调用DoModal之前。SetDialogBkColor(RGB(0,255,0),RGB(0,0,255));//前一个RGB是对话框的背景颜色,后一个RGB是文本颜色。都可以自己设定。
参见OPENFILENAME结构的lpfnHook成员的说明
http://www.csdn.net/Expert/topic/499/499189.shtm
m_bursh.CreateSolidBrush(RGB(255, 0, 0));
在函数OnCtlColor里使hbr = m_bursh;
{
...
// lets set red background and green text for our dialogs
SetDialogBkColor(RGB(255, 0, 0), RGB(0, 255, 0));
...
}
,[email protected]
,[email protected]
BOOL CMyApp::InitInstance()
{
...
// lets set red background and green text for our dialogs
SetDialogBkColor(RGB(255, 0, 0), RGB(0, 255, 0));
...
}
多谢您的帮助,这只能改变窗体的背景色和字体颜色,不能改变窗口中控件的背景色和前景色。