16,471
社区成员
发帖
与我相关
我的任务
分享
//假设你已有了名为My的对话框工程.你有了一个STATIC的控件,ID为IDC_STATIC1.
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
//如果要指定某个特定控件可以这样写:ID为IDC_STATIC1
if (pWnd-> GetDlgCtrlID()==IDC_STATIC1)
{
pDC-> SetTextColor(myColor); //设置字体颜色
pDC-> SetBkMode(TRANSPARENT); //设置字体背景为透明
// TODO: Return a different brush if the default is not desired
return (HBRUSH)::GetStockObject(BLACK_BRUSH); // 设置背景色
}
else
return hbr;
// TODO: Return a different brush if the default is not desired
return hbr;
}
HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
pDC->SetTextColor( m_ForeColor ); //设置文字颜色
pDC->SetBkColor( m_BackColor ); //设置背景色
return (HBRUSH)m_brush.GetSafeHandle(); //返回背景刷
// TODO: Return a non-NULL brush if the parent's handler should not be called
//return NULL;
}