How to draw the static part of the combobox

只愿长相守 提交于 2019-12-12 04:43:54

问题


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

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?


回答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;


来源:https://stackoverflow.com/questions/22267320/how-to-draw-the-static-part-of-the-combobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!