承接专栏《MFC工控项目实例二十一型号选择界面删除参数按钮禁用切换》
1、在SEAL_PRESSUREDlg.h文件中添加代码
class CSEAL_PRESSUREDlg : public CDialog
{
public:
CBrush m_brush1;
CBrush m_brush2;
CBrush m_brush3;
...
}
2、在SEAL_PRESSUREDlg.cpp文件中添加代码
BOOL CSEAL_PRESSUREDlg::OnInitDialog()
{
CDialog::OnInitDialog();
...
m_brush1.CreateSolidBrush(RGB(0,255,0));//绿色
m_brush2.CreateSolidBrush(RGB(255,0,0));//红色
m_brush3.CreateSolidBrush(RGB(255,255,255));//白色
...
}
HBRUSH CSEAL_PRESSUREDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if ((pWnd->GetDlgCtrlID() == IDC_STATIC_OK))
{
pDC->SetTextColor(RGB(255, 255, 255));//设置文本框字体颜色
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)m_brush1;
}
if ((pWnd->GetDlgCtrlID() == IDC_STATIC_NG))
{
pDC->SetTextColor(RGB(255, 255, 255));//设置文本框字体颜色pDC->SetBkMode(TRANSPARENT);//设透明
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)m_brush2;
}
if ((pWnd->GetDlgCtrlID() == IDC_STATIC_TOTAL))
{
pDC->SetTextColor(RGB(0, 0, 0));//设置文本框字体颜色pDC->SetBkMode(TRANSPARENT);//设透明
pDC->SetBkMode(RGB(255, 255, 255));
return (HBRUSH)m_brush3;
}
return hbr;
}
运行程序
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » MFC工控项目实例二十二主界面计数背景颜色改变
发表评论 取消回复