CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: CComboBox

  1. #1
    Join Date
    Jul 2000
    Location
    Brazil
    Posts
    26

    Question 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

  2. #2
    Join Date
    May 2002
    Location
    Poland
    Posts
    48
    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
  •  





Click Here to Expand Forum to Full Width

Featured