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.
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.
不过要修改成这样的
ON_NOTIFY(HDN_ITEMCHANGEDA, 0, OnItemchanged)
ON_NOTIFY(HDN_ITEMCHANGEDW, 0, OnItemchanged)
VC6下要需要这么写,否则无响应
谢谢,那些是加到CListCtrl的扩展类中吗?
但是我最终怎么在加载CListCtrl控件的窗口类中响应列头的双击事件呢?