void CGetList::OnItemclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
// TODO: Add your control notification handler code here

*pResult = 0;
}
在上面有phdn如何获得有关的参数,例如列表中的第几行。
还HD_NOTIFY是怎样的结构?

解决方案 »

  1.   

    上面消息是对HDN_ITEMCLICK消息的响应吧,其实,你要的消息应该是NM_CLICK。HDN_ITEMCLICK消息是在ListCtrl的header上click后产生的消息,而不是在item上click产生的消息。(ListCtrl的header是在LVS_REPORT状态下的“列 ”的“标题条”)
      

  2.   

    上面消息是对HDN_ITEMCLICK消息的响应吧,其实,你要的消息应该是NM_CLICK。HDN_ITEMCLICK消息是在ListCtrl的header上click后产生的消息,而不是在item上click产生的消息。(ListCtrl的header是在LVS_REPORT状态下的“列 ”的“标题条”)
      

  3.   

    typedef struct tagNMHDR { 
    HWND hwndFrom; 
    UINT idFrom; 
    UINT code; 
    } NMHDR;code Notification code. This member can be a control-specific notification code or it can be one of the common notification codes. The following values are not supported: NM_RCLICK 
    NM_RDBCLICK 
    -----------------------------------------------------------------
    typedef struct _HD_ITEM { hdi
    UINT mask; 
    int cxy; 
    LPSTR pszText; 
    HBITMAP hbm; 
    int cchTextMax; 
    int fmt; 
    LPARAM lParam; 
    } HD_ITEM;-----------------------------------------------------------------
    typedef struct _HD_NOTIFY { 
    NMHDR hdr; 
    int iItem; 
    int iButton; 
    HD_ITEM FAR *pitem; 
    } HD_NOTIFY;iItem Zero-based index of the header item that is the focus of the notification message. iButton Index of the mouse button used to generate the notification message. It is one of the following values:Value Description 
    0 Left button 
    1 Right button 
    2 Middle button -----------------------------------------------------------------
    一般WIN32中的 WM_NOTIFY 消息实际上会使用包含NMHDR型结构为第一个成员的结构指针,比如上面的 HD_NOTIFY, 因此在使用时必须先将其强制转换恢复本来面目。更多细节请参阅
    MSDN:
    TN061: ON_NOTIFY and WM_NOTIFY Messages
      

  4.   

    注意,NM_CLICK消息也并不完全是在某个item上click后产生的,只要在ListCtrl的client区域中click,就会产生这么个通知消息。但是,你可以响应这个消息,然后检查是否有哪个item被选中,如果有,选中的又是哪一个。你可以响应NM_CLICK,并调用下面的函数://///////////////////////////////////////////////////////////////////
    // GetSelectedListItem()
    // return value:
    // -1:  no list item
    // -2:  no selected list item
    // >=0:  index of selected list item
    //
    int GetSelectedListItem(CListCtrl& ctrlList)
    {
    int nCount = ctrlList.GetItemCount();
    if(nCount <= 0)
    {
    return -1; // no item
    } if(ctrlList.GetSelectedCount() == 0)
    {
    return -2; // no selection
    } LV_ITEM lvi;
    lvi.mask = LVIF_STATE | LVIF_PARAM;
    lvi.iSubItem = 0;
    lvi.stateMask = 0xFFFF; // get all state flags

    int nItemSel = -2; for (int i = 0; i < nCount; ++ i)
    {
    lvi.iItem = i;
    ctrlList.GetItem(&lvi);
    if((lvi.state & LVIS_SELECTED) != 0)
    {
    nItemSel = i;
    break;
    }
    } return nItemSel;
    }
      

  5.   

    注意,NM_CLICK通知消息在ListCtrl中的客户区click就会产生,并不是一定要click在某个item上才产生的。所以,正确的做法是,响应这个NM_CLICK消息,检查是否有item选中,如有,检查选中的是哪一个。下面的函数可以做这件事://///////////////////////////////////////////////////////////////////
    // GetSelectedListItem()
    // return value:
    // -1:  no list item
    // -2:  no selected list item
    // >=0:  index of selected list item
    //
    int GetSelectedListItem(CListCtrl& ctrlList)
    {
    int nCount = ctrlList.GetItemCount();
    if(nCount <= 0)
    {
    return -1; // no item
    } if(ctrlList.GetSelectedCount() == 0)
    {
    return -2; // no selection
    } LV_ITEM lvi;
    lvi.mask = LVIF_STATE | LVIF_PARAM;
    lvi.iSubItem = 0;
    lvi.stateMask = 0xFFFF; // get all state flags

    int nItemSel = -2; for (int i = 0; i < nCount; ++ i)
    {
    lvi.iItem = i;
    ctrlList.GetItem(&lvi);
    if((lvi.state & LVIS_SELECTED) != 0)
    {
    nItemSel = i;
    break;
    }
    } return nItemSel;
    }
      

  6.   

    以下拷贝自MSDN( header control 消息:HDN_ITEMCLICK
    hdr 
    NMHDR structure that contains information about the notification message. 
    iItem 
    Zero-based index of the header item that is the focus of the notification message. 
    iButton 
    Value specifying the index of the mouse button used to generate the notification message. This member can be one of the following values: 0  Left button 
    1  Right button 
    2  Middle button pitem 
    Optional pointer to an HDITEM structure containing information about the item specified by iItem. The mask member of the HDITEM structure indicates which of its members are valid. 
    =========================================
    以下是NM_CLICK相关
    lpnmitem = (LPNMITEMACTIVATE) lParam;
    信息:
    typedef struct tagNMITEMACTIVATE{
        NMHDR   hdr;
        int     iItem;
        int     iSubItem;
        UINT    uNewState;
        UINT    uOldState;
        UINT    uChanged;
        POINT   ptAction;
        LPARAM  lParam;
        UINT    uKeyFlags;
    } NMITEMACTIVATE, FAR *LPNMITEMACTIVATE;hdr 
    NMHDR structure that contains information about this notification message. 
    iItem 
    Index of the list view item. If the item index is not used for the notification, this member will contain -1. 
    iSubItem 
    One-based index of the subitem. If the subitem index is not used for the notification or the notification does not apply to a subitem, this member will contain zero. 
    uNewState 
    New item state. This member is zero for notification messages that do not use it. 
    uOldState 
    Old item state. This member is zero for notification messages that do not use it. 
    uChanged 
    Set of flags that indicate the item attributes that have changed. This member is zero for notifications that do not use it. Otherwise, it can have the same values as the mask member of the LVITEM structure. 
    ptAction 
    POINT structure that indicates the location at which the event occurred. This member is undefined for notification messages that do not use it. 
    lParam 
    Application-defined 32-bit value of the item. This member is undefined for notification messages that do not use it. 
    uKeyFlags 
    Modifier keys that were pressed at the time of the activation. This member contains zero or a combination of the following flags: LVKF_ALT  The ALT key is pressed.  
    LVKF_CONTROL  The CTRL key is pressed.  
    LVKF_SHIFT  The SHIFT key is pressed.  
      

  7.   

    不用这么麻烦吧
    SubitemHitTest