listctrl双击时,如何获取鼠标相对于listctrl的位置?GetCursorPos是获取鼠标的屏幕位置,如何将这两者进行转化呢

解决方案 »

  1.   

    m_listCtrl.ScreenToClient
    m_listCtrl是列表控件
      

  2.   

    GetCursorPos 获取屏幕位置然后ScreenToClient转化成相对listctrl的位置
    BOOL ScreenToClient(
      HWND hWnd,        // handle to window
      LPPOINT lpPoint   // screen coordinates
    );上面hWnd是listctrl的句柄。
      

  3.   

    我是这么实现的
            DWORD dwPos = GetMessagePos();
               CPoint point( LOWORD(dwPos), HIWORD(dwPos) );
      
               m_list.ScreenToClient(&point);
      
               LVHITTESTINFO lvinfo;
               lvinfo.pt = point;
               lvinfo.flags = LVHT_ABOVE;
        
               int nItem = m_list.SubItemHitTest(&lvinfo);