cneaton
asked on
Changing Text Color
I've created a Dialog-based application (using Visual C++) in which users enter in information and submit it to be processed. I have an edit control on the interface which will be used to display alert messages to the user if they enter in invalid information. I want the error message to appear in red and then in black when a new error occurs. However, I've been having a hard time finding information about changing text color in Edit Controls. It seems alot of people are interested in changing the background color, but I want to change the text color only.
Any ideas?? Thanks
Any ideas?? Thanks
goto: http://www.codeguru.com/editctrl/CEditExAndCStaticEx.shtml
and download the demo project and source, its exactly what u need.
good luck
and download the demo project and source, its exactly what u need.
good luck
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the code, hakob. But where would (or how) do I call the function to actually change the color. I want to display the text in red initially so I would have to call the function to invoke a change in text color (black -> red) and then I want to set the text back to black. How do I do that? I see the code that would be used to change the color. I just need to know how to invoke it.
Thanks!
Thanks!
ASKER
I found some code that could be used to enhance the CEdit class in order to allow text color changes. However, when I tried to run it, I got errors. Here is the code:
//////////////////////HEAD ER FILE
class ColorEdit : public CEdit
{
protected:
COLORREF m_clrText;
COLORREF m_clrBack;
CBrush m_brBkgnd;
public:
ColorEdit();
void SetTextColor (COLORREF clrText);
void SetBkColor (COLORREF clrBack);
HBRUSH m_hbrBack;
virtual ~ColorEdit();
protected:
afx_msg HBRUSH ONCtlColor(CDC *pCD, CWnd* pWnd, UINT nCtlColor);
DECLARE_MESSAGE_MAP()
};
//////////////////////IMPL EMENTATION
#include "ColorEdit.h"
#define RGBRED RGB(128,0,0)
#define RGBWHITE RGB(255,255,255)
#define RGBBLACK RGB(0,0,0)
ColorEdit::ColorEdit()
{
m_hbrBack = ::CreateSolidBrush(RGBRED) ;
}
ColorEdit::~ColorEdit()
{
::DeleteObject(m_hbrBack);
}
BEGIN_MESSAGE_MAP(ColorEdi t, CEdit)
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
ColorEdit::ColorEdit ()
{
m_clrText = RGBBLACK;
m_clrBack = ::GetSysColor(COLOR_3DFACE );
m_brBkgnd.CreateSolidBrush (m_clrBack );
}
void ColorEdit::SetTextColor(CO LORREF clrText)
{
m_clrText = clrText;
Invalidate();
}
HRBRUSH ColorEdit::CtlColor (CDC* pDC, UINT nCtlColor)
{
pDC->SetTextColor(m_clrTex t);
pDC->SetBkColor(m_clrBack) ;
return (HBRUSH)m_brBkgnd;
}
I think the most significant error I got was:
error C2504: 'CEdit' : base class undefined
I called it the most significant error because I think that correcting this problem would eliminate a host of others. Any suggestions as to what I'm doing wrong?
Thanks so much!!
//////////////////////HEAD
class ColorEdit : public CEdit
{
protected:
COLORREF m_clrText;
COLORREF m_clrBack;
CBrush m_brBkgnd;
public:
ColorEdit();
void SetTextColor (COLORREF clrText);
void SetBkColor (COLORREF clrBack);
HBRUSH m_hbrBack;
virtual ~ColorEdit();
protected:
afx_msg HBRUSH ONCtlColor(CDC *pCD, CWnd* pWnd, UINT nCtlColor);
DECLARE_MESSAGE_MAP()
};
//////////////////////IMPL
#include "ColorEdit.h"
#define RGBRED RGB(128,0,0)
#define RGBWHITE RGB(255,255,255)
#define RGBBLACK RGB(0,0,0)
ColorEdit::ColorEdit()
{
m_hbrBack = ::CreateSolidBrush(RGBRED)
}
ColorEdit::~ColorEdit()
{
::DeleteObject(m_hbrBack);
}
BEGIN_MESSAGE_MAP(ColorEdi
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
ColorEdit::ColorEdit ()
{
m_clrText = RGBBLACK;
m_clrBack = ::GetSysColor(COLOR_3DFACE
m_brBkgnd.CreateSolidBrush
}
void ColorEdit::SetTextColor(CO
{
m_clrText = clrText;
Invalidate();
}
HRBRUSH ColorEdit::CtlColor (CDC* pDC, UINT nCtlColor)
{
pDC->SetTextColor(m_clrTex
pDC->SetBkColor(m_clrBack)
return (HBRUSH)m_brBkgnd;
}
I think the most significant error I got was:
error C2504: 'CEdit' : base class undefined
I called it the most significant error because I think that correcting this problem would eliminate a host of others. Any suggestions as to what I'm doing wrong?
Thanks so much!!
include MFC-headers !
http://codeguru.earthweb.com/editctrl/CEditExAndCStaticEx.shtml