troubleshooting Question

Change Text color of CEdit, but OnCtlColor(...) is never called

Avatar of Sonja_M
Sonja_MFlag for Switzerland asked on
C++System ProgrammingMicrosoft Development
5 Comments1 Solution5040 ViewsLast Modified:
Hello my Expert-Friends!

I want to colorize the Text of an Edit Field. I read in the net this is the way to do it but the "HBRUSH CKGEdit::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)"-function is never called. Why?

Greedings

Sonja
// KGEdit.h
//----------
 
class CKGEdit : public CEdit
{
// Construction
public:
  CKGEdit();
 
protected:
	//{{AFX_MSG(CKGEdit)
	afx_msg void OnChange();
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	//}}AFX_MSG
  
	DECLARE_MESSAGE_MAP()
};
 
// KGEdit.cpp
//------------
 
CKGEdit::CKGEdit()
{
}
 
BEGIN_MESSAGE_MAP(CKGEdit, CEdit)
	//{{AFX_MSG_MAP(CKGEdit)
	ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
void CKGEdit::OnChange() 
{
}
 
HBRUSH CKGEdit::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
  HBRUSH hbr = CEdit::OnCtlColor(pDC, pWnd, nCtlColor);
  COLORREF myColor = RGB(110, 185, 250);
  pDC->SetTextColor(myColor);
  return hbr;
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros