<!-- Download Links -->
<!-- Article image -->
<!-- Add the rest of your HTML here -->
I created these two classes to make changing the color of your Edit Box
text and your Static text easy. I didn't need all the overhead of a
CRichEditCtrl , but I did need to change the color of my text
as well as the background color of the box.
CStatic didn't have an easy
way of changing the color of your text either.
These classes are derived from
How to Use
Include the files ColorEdit.cpp, ColorEdit.h and Color.h in
your project if your just working with Edit Boxes. If you want to
incorporate colored static text also you would add the files ColorStatic.cpp,
In your dialogs header file add :
#include "ColorStatic.h" //only if using colored static text.
There are two ways you can associate your control id's with the classes.
From now on I will assume you are using both classes.
In your dialogs .cpp file add :
void YourDlg::DoDataExchange(CDataExchange* pDX)
DDX_Control(pDX, IDC_ST_TEXT, m_stText);
DDX_Control(pDX, IDC_EB_CTL, m_ebCtl);
Now that this is finished it is time to use the class. There are three
functions available for Edit Boxes and two for Static Text.
They are as follows:
There are three functions available Currently:
SetBkColor(COLORREF crColor) SetTextColor(COLORREF crColor) SetReadOnly(BOOL flag = TRUE)
In the file Color.h is the following code:
#define RED RGB(127, 0, 0)
#define GREEN RGB( 0,127, 0)
#define BLUE RGB( 0, 0,127)
#define LIGHTRED RGB(255, 0, 0)
#define LIGHTGREEN RGB( 0,255, 0)
#define LIGHTBLUE RGB( 0, 0,255)
#define BLACK RGB( 0, 0, 0)
#define WHITE RGB(255,255,255)
#define GRAY RGB(192,192,192)
These are just a few I picked out but add as many colors as you need.
Here is how easy it is to use:
m_ebCtl.SetTextColor(BLUE); m_ebCtl.SetBkColor(WHITE); m_ebCtl.SetReadOnly(); m_stText.SetTextColor(RED); m_stText.SetBkColor(GREEN);
I hope someone out there finds this useful