Colors App
• Declare 3 variables in CColors.h
………………………………..
public:
COLORREF m_clrText;
COLORREF m_clrBkgnd;
CBrush m_brBkgnd;
};
• Initialize the variab in the constructor of CColors.cpp
CColors::CColors()
{
m_clrText = RGB(0, 0, 0);
m_clrBkgnd = RGB(255, 255, 255);
m_brBkgnd.CreateSolidBrush(m_clrBkgnd);
}
CColors.cpp
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;
}
• Add 2 variables in ColorsDlg.h to get the values
from the var of CColors: m_clrText, m_clrBkgnd.
ColorsDlg.h
#include "CColors.h“
…………………………………..
public:
CColors m_edit;
COLORREF m_culText;
COLORREF m_culBkgnd;
};
• Initialize the variables in CColorsDlg::OnInitDialog() of
ColorsDlg.cpp:
……………………………………….
// TODO: Add extra initialization here
m_culText = RGB(0, 0, 0);
m_culBkgnd = RGB(255, 255, 255);
return TRUE; // return TRUE unless you set the
focus to a control
}
void CColorsDlg::OnClickedButton1()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
dlg.DoModal();
m_culText = dlg.GetColor();
m_edit.m_clrText = m_culText;
RedrawWindow();
}
void CColorsDlg::OnClickedButton2()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
dlg.DoModal();
m_culBkgnd = dlg.GetColor();
m_edit.m_clrBkgnd = m_culBkgnd;
RedrawWindow();
}

MFC Colors app

  • 1.
  • 15.
    • Declare 3variables in CColors.h ……………………………….. public: COLORREF m_clrText; COLORREF m_clrBkgnd; CBrush m_brBkgnd; };
  • 16.
    • Initialize thevariab in the constructor of CColors.cpp CColors::CColors() { m_clrText = RGB(0, 0, 0); m_clrBkgnd = RGB(255, 255, 255); m_brBkgnd.CreateSolidBrush(m_clrBkgnd); }
  • 19.
    CColors.cpp 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; }
  • 22.
    • Add 2variables in ColorsDlg.h to get the values from the var of CColors: m_clrText, m_clrBkgnd. ColorsDlg.h #include "CColors.h“ ………………………………….. public: CColors m_edit; COLORREF m_culText; COLORREF m_culBkgnd; };
  • 23.
    • Initialize thevariables in CColorsDlg::OnInitDialog() of ColorsDlg.cpp: ………………………………………. // TODO: Add extra initialization here m_culText = RGB(0, 0, 0); m_culBkgnd = RGB(255, 255, 255); return TRUE; // return TRUE unless you set the focus to a control }
  • 28.
    void CColorsDlg::OnClickedButton1() { // TODO:Add your control notification handler code here CColorDialog dlg; dlg.DoModal(); m_culText = dlg.GetColor(); m_edit.m_clrText = m_culText; RedrawWindow(); }
  • 33.
    void CColorsDlg::OnClickedButton2() { // TODO:Add your control notification handler code here CColorDialog dlg; dlg.DoModal(); m_culBkgnd = dlg.GetColor(); m_edit.m_clrBkgnd = m_culBkgnd; RedrawWindow(); }