The answer from above link is in the right direction, however it is not implemented correctly. CtlColor
should return a brush handle. It also needs to set text background color with CDC::SetBkColor
class cmfc_edit : public CMFCEditBrowseCtrl
{
public:
COLORREF bkcolor;
CBrush brush;
void setBrushColor(COLORREF clr)
{
bkcolor = clr;
brush.DeleteObject();
brush.CreateSolidBrush(clr);
}
HBRUSH CtlColor(CDC* pDC, UINT)
{
if (!brush.GetSafeHandle())
return GetSysColorBrush(COLOR_WINDOW);
pDC->SetBkColor(bkcolor);
return brush;
}
//optional, change color on focus change
void OnSetFocus(CWnd* w)
{
setBrushColor(RGB(255, 0, 0));
CMFCEditBrowseCtrl::OnSetFocus(w);
}
void OnKillFocus(CWnd* w)
{
setBrushColor(RGB(255, 255, 255));
CMFCEditBrowseCtrl::OnKillFocus(w);
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(cmfc_edit, CMFCEditBrowseCtrl)
ON_WM_CTLCOLOR_REFLECT()
//optional
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
END_MESSAGE_MAP()
usage:
mfc_edit.setBrushColor(RGB(255, 0, 0));