我的消息映射函数
afx_msg HBRUSH OnCtlColor(CDC *pDC,CWnd *pWnd,UINT nCtlColor);
我的函数实现
HBRUSH CMFCTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID() == IDC_EDIT1)
{
pDC->SetTextColor(RGB(255,0,0)); //设置字体颜色
pDC->SetBkMode(TRANSPARENT); //设置字体背景为透明
// TODO: Return a different brush if the default is not desired
return (HBRUSH)::GetStockObject(BLACK_BRUSH); // 设置背景色
}
else
return hbr;
}
我这里有一个IDC_EDIT1的文本框控件,但是颜色并没有改变,不知道是为什么?我刚开始使用MFC
先把这一行代码注释试试, 如果不行.再回复我;
// return (HBRUSH)::GetStockObject(BLACK_BRUSH); // 设置背景色