如何在Listctrl 中接收Headerctrl 的通知消息

本文介绍在Windows XP系统使用Visual C++ 6.0开发环境中,如何为自定义的列表控件CMyListCtrl正确处理HDN_ITEMCHANGED消息。通过调整消息映射,确保能够接收到必要的通知消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境: winxp, vc6

 

新建一个dialog工程, 在对话框资源中加入一个listctrl,

 

从CListCtrl 继承一个类CMyListCtrl,

 

要在CMyListCtrl处理HDN_ITEMCHANGED,可用ClassWizard 添加一个消息处理函数:

 

BEGIN_MESSAGE_MAP(CMyList, CListCtrl)
 //{{AFX_MSG_MAP(CMyList)
 ON_NOTIFY_REFLECT(HDN_ITEMCHANGED, OnItemChanged)

 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

 

接下来必须手动作如下更改:

BEGIN_MESSAGE_MAP(CMyList, CListCtrl)
 //{{AFX_MSG_MAP(CMyList)
 ON_NOTIFY(HDN_ITEMCHANGEDW,0, OnItemChanged)

 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

 

即把反射消息改为通知消息,并且HDN_ITEMCHANGED要加上W,这样就可以接收HDN_ITEMCHANGED

 

补充说明:

HDN_TRACK消息跟windows 的 "Show window contents while dragging" 有关,如msdn阐述:

 

INFO: HDN_TRACK Notifications and Full Window Drag Style

ID: Q183258

 

If you are using Windows 95 with Microsoft Plus! or Windows NT 4.0, the user can enable full dragging of windows. You can do this in the Microsoft Plus! Property page in the "Display" control panel property sheet. If the "Show window contents while dragging" check box is selected, multiple HDN_ITEMCHANGING notifications will be sent and the HDN_TRACK notification message will not be sent. If the check box is not selected, the opposite will happen--multiple HDN_ITEMCHANGING notifications will not be sent and the HDN_TRACK notification message will be sent.

You can set and retrieve the full window drag feature programmatically by using the SystemParametersInfo function with the SPI_SETFULLDRAGWINDOW to set it and the SPI_GETDRAGFULLWINDOWS options to retrieve it.

The following code shows how to check to see if full window dragging is enabled and, if so, remove the HDS_FULLDRAG style from the list view control's header control.

 

可在CMyListCtrl的PreSubclassWindow作如下处理:

 

ModifyStyle(HDS_FULLDRAG,0);

 

去掉HDS_FULLDRAG,就可以接收HDN_TRACK消息,ok

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值