CListCtrl的OndrawItem()是如何被FrameWork调用的?

arccpp 2003-08-24 09:42:03
在msdn上查了半天也没找到:(
什么样的情况会触发WM_DRAWITEM消息呀
...全文
177 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
arccpp 2003-08-25
  • 打赏
  • 举报
回复
可何时控件会发生重绘呢
zhouyong0371 2003-08-25
  • 打赏
  • 举报
回复
只有当你的Owner Draw属性的控件需要重画的时候,才会进去
ListCtrl的Item不为空就可以进去了。
arccpp 2003-08-25
  • 打赏
  • 举报
回复
up
arccpp 2003-08-24
  • 打赏
  • 举报
回复
up
arccpp 2003-08-24
  • 打赏
  • 举报
回复
我选中了Owner_Draw风格,在OnDrawItem()函数中设置了断点,可调试的时候并没有停在我设断点的位置,怎么回事
zhouyong0371 2003-08-24
  • 打赏
  • 举报
回复
如你在ListCtrl的属性页的Style页Owner Draw选中Fixed
然后添加代码:
void CListCtrlOwnerDrawDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default

if (lpDrawItemStruct->CtlType == ODT_LISTBOX)
{
HBRUSH hBrush ;
hBrush=CreateSolidBrush(RGB(213,192,228));
hBrush=(HBRUSH) SelectObject (lpDrawItemStruct->hDC,hBrush);
SetBkColor(lpDrawItemStruct->hDC,RGB(213,192,228));
SetTextColor(lpDrawItemStruct->hDC,RGB(0,0,255));
Rectangle(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
DeleteObject(SelectObject(lpDrawItemStruct->hDC,hBrush));
}

}

点一下ListCtrl就可以看到结果了,这只是一个简单的示例,具体要你自己实现。

zhouyong0371 2003-08-24
  • 打赏
  • 举报
回复
CWnd::OnDrawItem
This method is called by the framework for the owner of an owner-draw button control, combo-box control, list-box control, or menu when a visual aspect of the control or menu has changed.

afx_msg void OnDrawItem(
int nIDCtl,
LPDRAWITEMSTRUCT lpDrawItemStruct );

也就是说,如果你的ListCtrl如果是具有Owner Draw属性的,就会在窗体就会在这个ListCtrl需要重画的任何时候响应OnDrawItem
在这里边可以处理
ODT_BUTTON Owner-drawn button
ODT_COMBOBOX Owner-drawn combo box
ODT_LISTBOX Owner-drawn list box
ODT_MENU Owner-drawn menu
ODT_LISTVIEW List view control
ODT_STATIC Owner-drawn static control
ODT_TAB Tab control
等类型的具有Owner Draw属性的控件。
arccpp 2003-08-24
  • 打赏
  • 举报
回复
up2

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧