我在一个对话框里有一个 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 如果操作也没有一个消息处理函数被执行。
请问各位大侠,怎样才能响应 HDN_ 打头的消息?

解决方案 »

  1.   

    YOu have  corresponding #define#ifdef UNICODE  <- is UNICODE, no ...
    #define HDN_ITEMCHANGING         HDN_ITEMCHANGINGW 
    #else           <- otherwise this
    #define HDN_ITEMCHANGING         HDN_ITEMCHANGINGA 
    #endif If you have problem eith notification codes be sure you've #include -ed corresponding .h fileHope this helps
      

  2.   

    HDN_开头的消息是Notify消息,他会把消息发给其父窗口即HEADER的父窗口ListCtrl,所以你应该重载Listctrl,在ListCtrl里边用
    ON_NOTIFY_REFLECT(HDN_ITEMCLICK, OnItemclickList2)
    处理消息!
      

  3.   

    96163(爱谁谁):
    我在 CListView 中处理过 HDN_ITEMCLICK
    ON_NOTIFY_REFLECT(HDN_ITEMCLICK, OnItemclick)但是也不会执行,这与重载CListCtrl应该是差不多的,不知什么原因。估计重载CListCtrl也不会招执行,另我主要是为了处理CListView继承下来的类。
      

  4.   

    cbc(逍遥子):
    我的程序配置是非UNICODE的,我把 HDN_ITEMCHANGING 对应的数据用输出过,与此消息对应的 HDN_ITEMCHANGINGA 的定义相同等于 -300, hex:fffffed4 。所以不会是这种问题。
      

  5.   

    把ON_NOTIFY(HDN_ITEMCHANGING, IDC_LIST1, OnItemchangingList1)改为
    ON_NOTIFY(HDN_ITEMCHANGING, 0, OnItemchangingList1)
    试试...理由见此:http://www.codeproject.com/listctrl/headerctrl.asp
    摘:
    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.
      

  6.   

    以上方法我没试过...
    因为我的ListCtrl是一个派生类...
    默认是ON_NOTIFY_REFLECT(HDN_ITEMCLICK, OnItemclick)
    结果响应不上...于是我改为
    ON_NOTIFY(HDN_ITEMCLICK,0, OnItemclick)
    后响应了
      

  7.   

    对的用派生类然后把 ON_NOTIFY_REFLECT 改为 ON_NOTIFY 就可以了,原来的ClassWizard 的错,哈哈……,
    谢谢 kingcom_xu(刀是用来杀人的!) ,
    也感谢大家的关心。
      

  8.   

    对、对,是应该把ON_NOTIFY_REFLECT 改为 ON_NOTIFY !
    我也明白了!
      

  9.   

    如果从CHeaderCtrl派生类的化就要用ON_NOTIFY_REFLECT了,我搞错了,呵呵!