DragDropListCtrl.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #if !defined(AFX_DRAGDROPLISTCTRL_H__17F6D56D_591C_4319_B0EB_9D6D9B45BC79__INCLUDED_)
  2. #define AFX_DRAGDROPLISTCTRL_H__17F6D56D_591C_4319_B0EB_9D6D9B45BC79__INCLUDED_
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif
  6. class CDragDropListCtrl : public CListCtrl
  7. {
  8. protected:
  9. // 要被拖动的1个或多个项的索引数组;
  10. CDWordArray m_anDragIndexes;
  11. // 当前被拖动项替换的项索引;
  12. int m_nDropIndex;
  13. // 拖动时的图标;
  14. CImageList* m_pDragImage;
  15. // 上一个索引;
  16. int m_nPrevDropIndex;
  17. // 上一个状态;
  18. UINT m_uPrevDropState;
  19. DWORD m_dwStyle;
  20. // 保存拖动的起始坐标;
  21. CPoint m_ptStart;
  22. // 当前移动的坐标点;
  23. CPoint m_ptCurr;
  24. // 移动起始点与当前坐标点间的所有项;
  25. void MoveDragItem(CPoint ptMove);
  26. enum EScrollDirection
  27. {
  28. scrollNull,
  29. scrollUp,
  30. scrollDown
  31. };
  32. EScrollDirection m_ScrollDirection;
  33. UINT m_uScrollTimer;
  34. public:
  35. CDragDropListCtrl();
  36. bool IsDragging() const { return m_pDragImage != NULL; }
  37. public:
  38. virtual ~CDragDropListCtrl();
  39. protected:
  40. void DropItem();
  41. void DropItem(CPoint pt);
  42. void RestorePrevDropItemState();
  43. void UpdateSelection(int nDropIndex);
  44. void SetScrollTimer(EScrollDirection ScrollDirection);
  45. void KillScrollTimer();
  46. CImageList* CreateDragImageEx(LPPOINT lpPoint);
  47. // 获取点所对应的项矩形;
  48. int GetPtItemIndex(CPoint pt);
  49. protected:
  50. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  51. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  52. afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
  53. afx_msg void OnTimer(UINT nIDEvent);
  54. DECLARE_MESSAGE_MAP()
  55. };
  56. #endif