Check
Add class CColors to manage the colors:
Declare 2 variables in CColors.h to manage the colors:
…………………….
public:
COLORREF m_clrText;
COLORREF m_clrBkgnd;
CBrush m_brBkgnd;
Initiatize the var in the constructor of the CColors.cpp
CColors::CColors()
{
m_clrText = RGB(0, 0, 0);
m_clrBkgnd = RGB(255, 255, 255);
m_brBkgnd.CreateSolidBrush(m_clrBkgnd);
}
HBRUSH CColors::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
pDC->SetTextColor(m_clrText);
pDC->SetBkColor(m_clrBkgnd);
// TODO: Return a non-NULL brush if the parent's handler
should not be called
return m_brBkgnd;
//return NULL;
}
void CCheckDlg::OnClickedCheck1()
{
// TODO: Add your control notification handler code here
if (IsDlgButtonChecked(IDC_CHECK1))
m_edit.m_clrText = RGB(255, 0, 0);
else
m_edit.m_clrText = RGB(0, 0, 0);
RedrawWindow();
}
void CCheckDlg::OnClickedCheck2()
{
// TODO: Add your control notification handler code here
if (IsDlgButtonChecked(IDC_CHECK2))
m_edit.m_clrBkgnd = RGB(0, 255, 0);
else
m_edit.m_clrBkgnd = RGB(255, 255, 255);
RedrawWindow();
}
In CheckDlg.h
#include "CColors.h"

MFC Check

  • 1.
  • 11.
    Add class CColorsto manage the colors:
  • 15.
    Declare 2 variablesin CColors.h to manage the colors: ……………………. public: COLORREF m_clrText; COLORREF m_clrBkgnd; CBrush m_brBkgnd;
  • 16.
    Initiatize the varin the constructor of the CColors.cpp CColors::CColors() { m_clrText = RGB(0, 0, 0); m_clrBkgnd = RGB(255, 255, 255); m_brBkgnd.CreateSolidBrush(m_clrBkgnd); }
  • 20.
    HBRUSH CColors::CtlColor(CDC* pDC,UINT nCtlColor) { // TODO: Change any attributes of the DC here pDC->SetTextColor(m_clrText); pDC->SetBkColor(m_clrBkgnd); // TODO: Return a non-NULL brush if the parent's handler should not be called return m_brBkgnd; //return NULL; }
  • 27.
    void CCheckDlg::OnClickedCheck1() { // TODO:Add your control notification handler code here if (IsDlgButtonChecked(IDC_CHECK1)) m_edit.m_clrText = RGB(255, 0, 0); else m_edit.m_clrText = RGB(0, 0, 0); RedrawWindow(); }
  • 32.
    void CCheckDlg::OnClickedCheck2() { // TODO:Add your control notification handler code here if (IsDlgButtonChecked(IDC_CHECK2)) m_edit.m_clrBkgnd = RGB(0, 255, 0); else m_edit.m_clrBkgnd = RGB(255, 255, 255); RedrawWindow(); }
  • 33.