1 // Color.h
2 // Colorref's to use with your Programs
3
4 #define RED RGB(127, 0, 0)
5 #define GREEN RGB( 0,127, 0)
6 #define BLUE RGB( 0, 0,127)
7 #define LIGHTRED RGB(255, 0, 0)
8 #define LIGHTGREEN RGB( 0,255, 0)
9 #define LIGHTBLUE RGB( 0, 0,255)
10 #define BLACK RGB( 0, 0, 0)
11 #define WHITE RGB(255,255,255)
12 #define GRAY RGB(192,192,192)
13
14 ///////////////////////////////////////////
15
16
17 #include "color.h"
18 /////////////////////////////////////////////////////////////////////////////
19 // CColorStatic window
20 class CColorStatic : public CStatic
21 {
22 // Construction
23 public:
24 void SetTextColor(COLORREF crColor); // This Function is to set the Color for the Text.
25 void SetBkColor(COLORREF crColor); // This Function is to set the BackGround Color for the Text.
26 CColorStatic();
27
28 // Overrides
29 // ClassWizard generated virtual function overrides
30 //{{AFX_VIRTUAL(CColorStatic)
31 //}}AFX_VIRTUAL
32
33 virtual ~CColorStatic();
34
35 // Generated message map functions
36 protected:
37 //{{AFX_MSG(CColorStatic)
38
39 CBrush m_brBkgnd; // Holds Brush Color for the Static Text
40 COLORREF m_crBkColor; // Holds the Background Color for the Text
41 COLORREF m_crTextColor; // Holds the Color for the Text
42
43 afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
44 //}}AFX_MSG
45
46 DECLARE_MESSAGE_MAP()
47 };
48
49
1 // ColorEdit.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "ColorEdit.h"
6 #include "Color.h" // File Holding (#define)'s for COLORREF Values
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CColorEdit
16
17 CColorEdit::CColorEdit()
18 {
19 m_crBkColor = ::GetSysColor(COLOR_3DFACE); // Initializing background color to the system face color.
20 m_crTextColor = BLACK; // Initializing text color to black
21 m_brBkgnd.CreateSolidBrush(m_crBkColor); // Creating the Brush Color For the Edit Box Background
22 }
23
24 CColorEdit::~CColorEdit()
25 {
26 }
27
28
29 BEGIN_MESSAGE_MAP(CColorEdit, CEdit)
30 //{{AFX_MSG_MAP(CColorEdit)
31 ON_WM_CTLCOLOR_REFLECT()
32 //}}AFX_MSG_MAP
33 END_MESSAGE_MAP()
34
35 /////////////////////////////////////////////////////////////////////////////
36 // CColorEdit message handlers
37
38 void CColorEdit::SetTextColor(COLORREF crColor)
39 {
40 m_crTextColor = crColor; // Passing the value passed by the dialog to the member varaible for Text Color
41 RedrawWindow();
42 }
43
44 void CColorEdit::SetBkColor(COLORREF crColor)
45 {
46 m_crBkColor = crColor; // Passing the value passed by the dialog to the member varaible for Backgound Color
47 m_brBkgnd.DeleteObject(); // Deleting any Previous Brush Colors if any existed.
48 m_brBkgnd.CreateSolidBrush(crColor); // Creating the Brush Color For the Edit Box Background
49 RedrawWindow();
50 }
51
52
53
54 HBRUSH CColorEdit::CtlColor(CDC* pDC, UINT nCtlColor)
55 {
56 HBRUSH hbr;
57 hbr = (HBRUSH)m_brBkgnd; // Passing a Handle to the Brush
58 pDC->SetBkColor(m_crBkColor); // Setting the Color of the Text Background to the one passed by the Dialog
59 pDC->SetTextColor(m_crTextColor); // Setting the Text Color to the one Passed by the Dialog
60
61 if (nCtlColor) // To get rid of compiler warning
62 nCtlColor += 0;
63
64 return hbr;
65 }
66
67 BOOL CColorEdit::SetReadOnly(BOOL flag)
68 {
69 if (flag == TRUE)
70 SetBkColor(m_crBkColor);
71 else
72 SetBkColor(WHITE);
73
74 return CEdit::SetReadOnly(flag);
75 }
76
77