如果在程序中响应CListCtrl控件的表头双击事件?

King_hhuang 2011-01-13 04:13:53
我的界面上放有一个CListCtrl控件,我想在双击表头的时候弹出一个设置表头属性的对话框,该怎么在我的程序中响应CListCtrl的表头双击事件呢?
...全文
488 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
King_hhuang 2011-01-13
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 varding 的回复:]
你在CListCtrl的派生类里调用你窗口中的处理函数就行了,或者发个自定义消息到窗口
[/Quote]

谢谢,你这样是可以实现,但是就没办法直接在窗口中响应列头双击的消息吗?
varding 2011-01-13
  • 打赏
  • 举报
回复
你在CListCtrl的派生类里调用你窗口中的处理函数就行了,或者发个自定义消息到窗口
King_hhuang 2011-01-13
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 visualeleven 的回复:]
重写CListCtrl类,添加处理HDN_开头的消息
不过要修改成这样的
ON_NOTIFY(HDN_ITEMCHANGEDA, 0, OnItemchanged)
ON_NOTIFY(HDN_ITEMCHANGEDW, 0, OnItemchanged)
VC6下要需要这么写,否则无响应
[/Quote]

这个可以在扩展类中响应,但是怎么才能在我加载这个扩展类的窗体中响应呢?
King_hhuang 2011-01-13
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 visualeleven 的回复:]
重写CListCtrl类,添加处理HDN_开头的消息
不过要修改成这样的
ON_NOTIFY(HDN_ITEMCHANGEDA, 0, OnItemchanged)
ON_NOTIFY(HDN_ITEMCHANGEDW, 0, OnItemchanged)
VC6下要需要这么写,否则无响应
[/Quote]

谢谢,那些是加到CListCtrl的扩展类中吗?
但是我最终怎么在加载CListCtrl控件的窗口类中响应列头的双击事件呢?
Eleven 2011-01-13
  • 打赏
  • 举报
回复
重写CListCtrl类,添加处理HDN_开头的消息
不过要修改成这样的
ON_NOTIFY(HDN_ITEMCHANGEDA, 0, OnItemchanged)
ON_NOTIFY(HDN_ITEMCHANGEDW, 0, OnItemchanged)
VC6下要需要这么写,否则无响应
Eleven 2011-01-13
  • 打赏
  • 举报
回复
Handling Notification Messages
Handling CHeaderCtrl messages in a CListCtrl strains ClassWizard's magic powers. The problem is that ClassWizard considers the CHeaderCtrl embedded in a CListCtrl to be of the same "message depth" as any other Common Control (CButton or CEdit Control, for instance). In practice however, the CHeaderCtrl is actually a child of the CListCtrl in which it resides. While the CListCtrl's immediate parent is the CDialog in which it is instantiated, the CHeaderCtrl's immediate parent is the CListCtrl. This is also suggested by the following two points:

Unlike other Common Controls on a CDialog, the CHeaderCtrl in the CListCtrl is not given an explicit resource ID;
The existence of the CListCtrl::GetHeaderCtrl(...) method
This problem arises when you use ClassWizard to create CHeaderCtrl handlers in a CDialog derived class. To create a CHeaderCtrl message handler, you first right click the CListCtrl object in the Resource Editor and select ClassWizard from the popup menu. ClassWizard then enumerates all the messages for this CListCtrl, including those sent by the CHeaderCtrl window. These messages are handled through the ON_NOTIFY macro construction. The list looks something like this:

Attempting to implement a message handler for HDN_<X> messages using Class Wizard will then generate an incorrect Message Map entry. For instance, creating a message handler for the HDN_ENDDRAG message will create an entry such as: ON_NOTIFY(HDN_ENDDRAG, IDC_LIST_CTRL, OnEnddragListCtrl). Unfortunately, the IDC_LIST_CTRL is not responsible for notifying the parent of a HDN_ENDDRAG message. It is the embedded CHeaderCtrl which sends the message, so the ON_NOTIFY macro should use the ID of the CHeaderCtrl. Using Spy++, we can determine that the ID of the CHeaderCtrl is 0, so the ON_NOTIFY entry needs to be manually edited to the following: ON_NOTIFY(HDN_ENDDRAG, 0, OnEnddragListCtrl). This roundabout way connects the WM_NOTIFY messages of the CHeaderCtrl to the "second-level" parent of the CHeaderCtrl, which is often where message processing is handled.
King_hhuang 2011-01-13
  • 打赏
  • 举报
回复
HDN_ITEMDBLCLICK有点像,可是我测试了一下,根本就没有反应啊
King_hhuang 2011-01-13
  • 打赏
  • 举报
回复
貌似还是没有左键双击事件啊,单击到是有
varding 2011-01-13
  • 打赏
  • 举报
回复
http://blog.csdn.net/bwmwm/archive/2008/07/24/2706663.aspx
varding 2011-01-13
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/en-us/library/bb775290(v=VS.85).aspx

http://www.cnblogs.com/niuniu502/archive/2007/03/12/672185.html
King_hhuang 2011-01-13
  • 打赏
  • 举报
回复
不是吧,CHeaderCtrl本来就有双击事件的啊,怎么把它引出来呢?
tigerMayDo 2011-01-13
  • 打赏
  • 举报
回复
双击事件中判断坐标?

15,980

社区成员

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

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