请问各位大侠如何CListView中的视图中响应ITEMDBLClICK事件?能实现吗,我没有找到相应的函数。HDN_ITEMDBLCLICK怎么用,最好能举个例子,谢谢了。

解决方案 »

  1.   

    原理:
    响应WM_LBUTTONDBLCLK消息,通过MOUSE点击点找到被双击的ITEM。操作:
    在你的CListCtrl派生类中唤出class wizard,选message maps,选WM_LBUTTONDBLCLK,按下Add Function,按edit code。代码:
    void CMyListCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CListCtrl::OnLButtonDblClk(nFlags, point); ClientToScreen(&point);
    CPoint pt(0,0);
    ::GetCursorPos(&pt);
    ScreenToClient(&pt); LVHITTESTINFO info;
    info.pt = pt;
    this->HitTest(&info); //do your work here.
    MessageBox("icelight?");
    }
      

  2.   

    info.iItem就是你想要的itemtypedef struct _LVHITTESTINFO { 
        POINT pt; 
        UINT flags; 
        int iItem; 
        int iSubItem;
     } LVHITTESTINFO, FAR *LPLVHITTESTINFO;
      

  3.   

    to icelight(icelight)
    对不起,能再问你一下吗,我是在单文档中的listview中GetListCtrl()中调用,怎么用啊!相应单击。
      

  4.   

    不用CListView,改用CFormView。用向导建好CMyFormView后,将头文件里的
    enum { IDD = _UNKNOWN_RESOURCE_ID_ };
    改为你建的dialog模板的ID。再用向导为模板里的list box建一个control的对象。然后在头文件里将CListCtrl m_list改为CMyListCtrl m_list就能用上面所写的代码了。
      

  5.   

    ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
    ---------------------
    void CListChildView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    // TODO: Add your control notification handler code here /*
    在这里添加响应列表控件的鼠标双击消息的代码
    相关数据结构:
    typedef struct tagNMHDR { 
    HWND hwndFrom; //消息句柄
    UINT idFrom; //控件id
    UINT code; //消息通知码
    } NMHDR; 
    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; //激发消息的列表框的item
    int iButton; //0:left button,1:right button,2:middle button
    HD_ITEM FAR *pitem; 
    } HD_NOTIFY;
    详细解释见msdn 例如:
    HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
    int nSelected=phdn->iItem;
    ......
    然后利用发送消息的方式与别的窗口通信!即可满足你的要求!
    */
    HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
    int nSelected=phdn->iItem;
    CMainFrame  *pFrame=(CMainFrame*)AfxGetMainWnd();
    //Send message to the mainframe windows!
    if(nSelected!=-1)//empty listctrl!
    pFrame->PostMessage(WM_MSG_FROM_LISTDLG,MAKELRESULT(nSelected+1, 0),0);} afx_msg LRESULT OnListenMessage(WPARAM wParam,LPARAM lParam);
    ON_MESSAGE(WM_MSG_FROM_LISTDLG,OnListenMessage)
    LRESULT  CMainFrame:: OnListenMessage(WPARAM wParam,LPARAM lParam)
    {
      int index=int(wParam);
      CString str;
      str.Format("You have choosed the the %dth item!",index);
      MessageBox(str);
      return true;
    }
    --------------
    程序的功能是,跟踪当前双击的列表框的item的位置!
    再mainframe 中相应消息
      

  6.   

    你只要明白了
    typedef struct tagNMHDR { 
    HWND hwndFrom; //消息句柄
    UINT idFrom; //控件id
    UINT code; //消息通知码
    } NMHDR; 
    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; //激发消息的列表框的item
    int iButton; //0:left button,1:right button,2:middle button
    HD_ITEM FAR *pitem; 
    } HD_NOTIFY;的结构就行了!
      

  7.   

    学习!谢谢 psusong(人类失去指针,世界将会怎样?),也谢谢 icelight(icelight) ,希望以后能多向你们请教,我的联系方式是[email protected],这就结贴
      

  8.   

    ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)