MFC的OnCtlColor为什么不能改变某些控件的背景色?
网上查到许多文章说,用OnCtlColor可以改变ListControl控件的背景色,我在VC++6.0和VS2013下都试过,不起作用。代码如下:
HBRUSH CListControlColorDlg::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_LISTBOX)
{
return m_brush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
并且将if语句改为if (pWnd->GetDlgCtrlID() == IDC_LIST_TEST)也不行。将if语句改为if (nCtlColor == CTLCOLOR_BTN)对按钮控件也不起作用。不知道为什么,哪位高手指点一下 。谢谢了!