如何绘制组合框的静态部分 [英] How to draw the static part of the combobox
问题描述
我有一个样式为CBS_DROPDOWNLIST
和CBS_OWNERDRAWVARIABLE
的自定义绘制组合框,我可以绘制下拉列表中的项目,但用户选择在组合框静态部分中绘制的项目选择项并显示选择项],我想给它一个自定义文本,如下图所示
但是我不能确定我找到了这样的代码
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);
}
但是当我使用它时,我得到的所有项目都有CtlType == ODT_COMBOBOX
,当我调试上面的代码时,它的静态部分返回ODT_COMBOBOX
,对于下拉列表的项目返回ODT_LISTBOX
.>
我想知道如何解决此问题,如何检测到我在下拉列表中绘制的是静态零件还是常规项目?
我只是检查ODS_COMBOBOXEDIT的状态.如果文档中说已为编辑控件设置了此标志,则它适用于下拉列表.
我已经检查了像您一样理智的组合框实现方式.
bool bDrawStaticControl = (pDIS->itemState & ODS_COMBOBOXEDIT)!=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
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?
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;
这篇关于如何绘制组合框的静态部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!