0

I want to know if it's possible to change the color of the text (and of the small arrow) and the background of the static in a CCombobox with the Drop List style.

My class is derived from CComboBox and I've tried with the function CtlColor and OnCtlColor, but nothing seems to change the color of the ComboBox.

Here's a picture of the control with the Drop List style :

ComboBoxDropList

I would like the text and the arrow to change to RGB(0, 255, 255) and the background to RGB(255,255,0).

Here's my function CtlColor() :

HBRUSH CColoredComboBox::CtlColor(CDC *pDC, UINT nCtlColor)
{
    if (nCtlColor == CTLCOLOR_STATIC || nCtlColor == CTLCOLOR_EDIT) 
    {
        pDC->SetBkColor(RGB(255,255,0));
        pDC->SetTextColor(RGB(0, 255, 255));
    }
    return m_brBkgnd;
}

It works for the style Dropdown, but not for the Drop List.

Thank you.

EylM
  • 5,967
  • 2
  • 16
  • 28
Emile
  • 592
  • 10
  • 36
  • Possible duplicate of [CBS\_DROPDOWNLIST combo fails to respond to WM\_CTLCOLOR... under Windows UX theming](https://stackoverflow.com/questions/10031621/cbs-dropdownlist-combo-fails-to-respond-to-wm-ctlcolor-under-windows-ux-themi) – zett42 Jul 10 '19 at 19:25
  • You can change the colour of the text and background by making the combobox owner draw. I know no way to change the colour of the arrow. – Paul Sanders Jul 10 '19 at 19:35
  • I think you have the names mixed up. Dropdown is the one with edit box, it won't work this method. Droplist has no edit box and it should work, provided you have the old 3-D look. The attached image shows modern UI look, so in that case neither listbox will show any change unless they are ownerdraw. – Barmak Shemirani Jul 11 '19 at 17:50

2 Answers2

0

Don't know arrow color can be changed or not but, color of combobox can be changed. With help of OnChildNotify() function, you can retrieve child HDC and then particular child HDC can be changed.

/////////////////////////////////////////////////////////////////////////////
// CMyComboBox message handlers

BOOL CMyComboBox::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) 
{
    // TODO: Add your specialized code here and/or call the base class

    if(WM_CTLCOLOREDIT != message)
        return CComboBox::OnChildNotify(message, wParam, lParam, pLResult);

    HDC hdcChild = (HDC)wParam;
    if(NULL != hdcChild)
    {
        SetBkMode(hdcChild, TRANSPARENT);
        SetTextColor(hdcChild, RGB(255, 255, 0));
        SetBkColor(hdcChild, RGB(255, 0, 0));
        *pLResult = (LRESULT)(m_Brush.GetSafeHandle());
    }

    return TRUE;
//  return CComboBox::OnChildNotify(message, wParam, lParam, pLResult);
}

Result:

Result

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Santosh Dhanawade
  • 1,756
  • 14
  • 29
0

There are two ways - easy and hard. The hard way is to complete DrawItem with ownerdraw to handle all the cases. The easy way is to put two combos on top of each other in your dialog resource and hide the one you're not going to use. Maybe this can give you some ideas.

Jeffreys
  • 431
  • 2
  • 8