Drawitem没有打电话 [英] Drawitem is not getting calling

查看:104
本文介绍了Drawitem没有打电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自己的自定义控件类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()函数,你必须进行控制所有者通过设置 CBS_OWNERDRAWVARIABLE 样式标志来绘制一个。这可以通过在调用 Create()时传递样式或在对话框模板中使用控件时在资源编辑器中指定相应选项来完成。
To get the DrawItem() function be called you have to make the control an owner drawn one by setting the CBS_OWNERDRAWVARIABLE style flag. This can be done by passing the style when calling Create() or specifying the corresponding option in the resource editor when using the contol in a dialog template.


这篇关于Drawitem没有打电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆