对于ListCtrl 的以 HDN_ 打头的消息映射函数都不会执行的问题
来源:百度文库 编辑:神马文学网 时间:2024/04/28 08:21:53
问题:
我在一个对话框里有一个 LISTCTRL (其ID为IDC_LIST1)并增加了以下消息映射:
ON_NOTIFY(HDN_ITEMCHANGING, IDC_LIST1, OnItemchangingList1)
ON_NOTIFY(HDN_ITEMCLICK, IDC_LIST1, OnItemclickList1)
ON_NOTIFY(HDN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
ON_NOTIFY(HDN_TRACK, IDC_LIST1, OnTrackList1)
并且 IDC_LIST1 具有 LVS_REPORT 风格。
但是程序执行过程中,对应的消息处理函数一个也不会执行,不管我对 LISTCTRL 中的 HEADCTRL 如果操作也没有一个消息处理函数被执行。
回答:
1、把ON_NOTIFY(HDN_ITEMCHANGING, IDC_LIST1, OnItemchangingList1)改为
ON_NOTIFY(HDN_ITEMCHANGING, 0, OnItemchangingList1)
试试...
理由见此:http://www.codeproject.com/KB/list/headerctrl.aspx
摘:
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_
回答2、
对于继承的类从ClassWizard添加HDN_ITEMCLICK消息响应,默认是ON_NOTIFY_REFLECT(HDN_ITEMCLICK, OnItemclick)
结果响应不上...改为
ON_NOTIFY(HDN_ITEMCLICK,0, OnItemclick)
后就响应了