0

I have a custom drawn combobox with style CBS_DROPDOWNLIST and CBS_OWNERDRAWVARIABLE I can draw the items of the dropdownlist ok but whe user select an item it is drawn in the combobox static part [the part of combo that stay visible after selecting item and show the selection], I want to give it a custom text like in the following image

enter image description here

But I can't determine it I found a code like this

    if(DrawItemStruct.CtlType == ODT_COMBOBOX)//the static part of the combo
        DrawComboText(pDC, DrawItemStruct.itemID, &DrawItemStruct.rcItem);
    else//the rest items
    {
        // Copy the text of the item to a string
        char sItem[256];
        GetString(sItem, DrawItemStruct.itemID);
        biDrawText(pDC, sItem, -1, &DrawItemStruct.rcItem, f | DT_VCENTER | DT_SINGLELINE);
    }

but when I used it I get all the items has CtlType == ODT_COMBOBOX, when I debugged the above code It return ODT_COMBOBOX for the static part, and for items of the drop down list it return ODT_LISTBOX.

I want to know how to fix this problem, how to detect that I'm drawing the static part or a regular item in the dropdown list?

embert
  • 7,336
  • 10
  • 49
  • 78
ahmedsafan86
  • 1,776
  • 1
  • 26
  • 49
  • 1
    Unclear to me. You seem to answer your own question: `ODT_COMBOBOX` for text in static control. `ODT_LISTBOX` for text from a Listbox item. That, or I didn't understand your question. – manuell Mar 08 '14 at 11:09
  • That is what I took from other source code but the ODT_LISTBOX never sent it was always ODT_COMBOBOX, in the source that I copied from it works fine, I don't know what I missed – ahmedsafan86 Mar 08 '14 at 13:48
  • I deal with the static portion by checking whether `DrawItemStruct.itemID == -1` – user1793036 Mar 10 '14 at 01:28
  • @user1793036 : that is OK if there is no selected item from the combo when you select item say item index = 2, then when the list is closed and while drawing the static part the itemID == 2. – ahmedsafan86 Mar 10 '14 at 07:49

1 Answers1

1

I just check the state for ODS_COMBOBOXEDIT. If ifthe dcumentation says that this flag is set for the edit Control, it works for the drop down list to.

I have checked combo box implementation like you that works in the sane way.

bool bDrawStaticControl = (pDIS->itemState & ODS_COMBOBOXEDIT)!=0;
xMRi
  • 14,982
  • 3
  • 26
  • 59