I can't changed texte color when controle is disabled.
I use the method described in MFC :
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
ON_MESSAGE(OCM_CTLCOLOREDIT, OnOcmCtlColorEdit)
ON_MESSAGE(OCM_CTLCOLORSTATIC, OnOcmCtlColorStatic)
...
/*--------------------------------------------------------------------------
------------
----------------------------------------------------------------------------
------------*/
LRESULT CCtEditBoxCtrl::OnOcmCtlColorEdit(WPARAM wParam, LPARAM lParam)
{
if (m_pBackBrush == NULL)
m_pBackBrush = new CBrush(RGB(0,0,0));
CDC* pdc = CDC::FromHandle((HDC)wParam);
pdc->SetBkMode(TRANSPARENT);
pdc->SetBkColor(m_enabledBackColor);
pdc->SetTextColor(m_enabledForeColor);
HBRUSH far* hbr = (HBRUSH far*)m_pBackBrush->GetSafeHandle();
return ((DWORD)hbr);
}
/*--------------------------------------------------------------------------
------------
----------------------------------------------------------------------------
------------*/
LRESULT CCtEditBoxCtrl::OnOcmCtlColorEdit(WPARAM wParam, LPARAM lParam)
{
if (m_pBackBrush == NULL)
m_pBackBrush = new CBrush(RGB(0,0,0));
CDC* pdc = CDC::FromHandle((HDC)wParam);
pdc->SetBkMode(TRANSPARENT);
pdc->SetBkColor(m_enabledBackColor);
pdc->SetTextColor(m_enabledForeColor);
HBRUSH far* hbr = (HBRUSH far*)m_pBackBrush->GetSafeHandle();
return ((DWORD)hbr);
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
Every thing works fine when Controle is enabled,
but when it is disabled back color change, but texte
color stay grey.
Which is the color obtained with "GetSysColor(COLOR_GRAYTEXT)"
I think ...
I don't understand why I can't change this color in my controle.
Can anyone help ?
Fulcanel wrote:
Hello Fulcanel!
You have to overwrite OnEraseBackground(), too...
ciao
Andreas
Well, ok but what should I do in "OnEraseBackground" ?
I don't want to change background color, but foreground (text) color...
Instead of disabling the edit control call "myEdit->SetReadOnly(TRUE)" !
-> If an edit control is disabled "OnCtlColor" is not called!