-
May 23rd, 2002, 02:55 PM
#1
CComboBox
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
-
May 23rd, 2002, 03:21 PM
#2
The MSDN says that the edit control sends WM_CTLCOLOREDIT to its parent (which is the combo box in this case). This message is handled by
CWnd::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );
where pWnd is the edit control. Maybe this would help.
regards,
MiMec
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|