承接专栏《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;
}
	

运行程序在这里插入图片描述

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部