问题描述
我创建了自己的自定义控件类CMyComboBox,它来自CCombobox。
i已将DrawItem添加为虚拟函数,但加载我的dailog时没有调用此函数
$ b $你能告诉我如何在这里打电话给我吗
2)我需要在这个班级中学习所有的组合框功能
你能给我一些建议吗? br />
我尝试过:
oid CMyComboBox :: DrawItem(LPDRAWITEMSTRUCT) lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct-> CtlType == ODT_COMBOBOX);
LPCTSTR lpszText =(LPCTSTR)lpDrawItemStruct-> itemData ;
ASSERT(lpszText!= NULL);
CDC dc;
dc.Attach(lpDrawItemStruct- > hDC);
//保存这些值以在完成绘图时恢复它们。
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = d c.GetBkColor();
//如果选择此项,请将背景颜色设置为
//并将文本颜色设置为合适值。擦除
//矩形填充背景颜色。
if((lpDrawItemStruct-> itemAction& ODA_SELECT)&&
(lpDrawItemStruct-> itemState& ODS_SELECTED))
{
dc.SetTextColor(:: GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(:: GetSysColor(COLOR_HIGHLIGHT));
dc.FillSolidRect(& lpDrawItemStruct-> rcItem,:: GetSysColor(COLOR_HIGHLIGHT));
}
else
{
dc.FillSolidRect(& lpDrawItemStruct-> rcItem,crOldBkColor);
}
//绘制文字。
dc.DrawText(
lpszText,
(int)_tcslen(lpszText),
& lpDrawItemStruct-> rcItem,
DT_CENTER | DT_SINGLELINE | DT_VCENTER);
//将背景颜色和文本颜色重置为
//原始值。
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
i have created my own custom control class CMyComboBox and its derived from CCombobox.
i have added DrawItem as virtual function but this function is not getting called when loading my dailog
could you please tell me how to call drawitem here
2) i need toget the all the combobox functionalities in this class
could you please give me some suggestions on this
What I have tried:
oid CMyComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX);
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
ASSERT(lpszText != NULL);
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
// Save these value to restore them when done drawing.
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
// If this item is selected, set the background color
// and the text color to appropriate values. Erase
// the rect by filling it with the background color.
if ((lpDrawItemStruct->itemAction & ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
}
// Draw the text.
dc.DrawText(
lpszText,
(int)_tcslen(lpszText),
&lpDrawItemStruct->rcItem,
DT_CENTER|DT_SINGLELINE|DT_VCENTER);
// Reset the background color and the text color back to their
// original values.
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
推荐答案
这篇关于Drawitem没有打电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!