Reputation: 5427
I want to change the background color of an item of a combobox when I use the method AddString.
Upvotes: 2
Views: 7033
Reputation: 11957
Derive a class from CComboBox and override OnCtlColor. In OnCtlColor when the nCtlColor parameter is CTLCOLOR_LISTBOX, call the DC::SetBkColor method.
Maybe something like this:
HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_LISTBOX)
pDC->SetBkColor(RGB(255, 0, 0));
return CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
}
Inspiration taken from here and here.
Upvotes: 4