Hi,

I am trying to write a class derivated from CComboBox which changes its background when the control gets the focus.

I overwrote the following member functions like this:



HBRUSH CMyComboBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
CEdit * pEdit = (CEdit *)GetWindow(GW_CHILD);
DWORD dwStyle = pEdit->GetStyle();

if( ( GetFocus() == pEdit ) && ( !( dwStyle & // If We Have The Focus
WS_DISABLED ) ) && ( !( dwStyle & // And Control Is Not Disabled
ES_READONLY ) ) ) // And Control Is Not ReadOnly
{
pDC -> SetTextColor( g_crATColor ); // Set Text Color
pDC -> SetBkColor( g_crABColor ); // Set Background Color

return( (HBRUSH)m_brBGBrush ); // Return Custom BG Brush
}
return( NULL );
}

BOOL CMyComboBox::OnEraseBkgnd(CDC* pDC)
{
CEdit * pEdit = (CEdit *)GetWindow(GW_CHILD);
DWORD dwStyle = pEdit->GetStyle();
CRect rClient;
BOOL bStatus = TRUE;

if( ( GetFocus() == pEdit ) && ( !( dwStyle & // If We Have The Focus
WS_DISABLED ) ) && ( !( dwStyle & // And Control Is Not Disabled
ES_READONLY ) ) ) // And Control Is Not ReadOnly
{
GetClientRect( &rClient ); // Get Our Area
pDC->FillSolidRect( rClient, g_crABColor ); // Repaint Background
}
else
{
bStatus = CComboBox::OnEraseBkgnd( pDC ); // Do Default
}
return( bStatus ); // Return Status
}



and I created messages map like this:

ON_CONTROL_REFLECT_EX(CBN_KILLFOCUS, OnKillFocusReflect)
ON_CONTROL_REFLECT_EX(CBN_SETFOCUS, OnSetFocusReflect)


BOOL CMyComboBox::OnKillFocusReflect( void )
{
CEdit * pEdit = (CEdit *)GetWindow(GW_CHILD);
pEdit->Invalidate();

Invalidate();

return( FALSE );
}


BOOL CMyComboBox::OnSetFocusReflect()
{
CEdit * pEdit = (CEdit *)GetWindow(GW_CHILD);
pEdit->Invalidate();

Invalidate();

return( FALSE );
}


The problem is that I can´t change the backcolor of the edit control inside the combobox. The combobox background is changed but the editbox doesn't.

Can someone help me?

Thanks in advance,

Vinicius