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

环境: 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

你可能感兴趣的:(windows,function,Microsoft,header,dialog,notifications)