1 #pragma once 2 #include "ColorConvert.h" 3 4 //鼠标拖动完成向父窗口发送此消息,通过wPara传递拖放结束的位置 5 //注意,执行拖动操作后列表项目的位置不会改变,需要在响应此消息后手动刷新列表 6 #define WM_LIST_ITEM_DRAGGED (WM_USER+121) 7 8 class CListCtrlEx : 9 public CListCtrl 10 { 11 DECLARE_DYNAMIC(CListCtrlEx) 12 public: 13 CListCtrlEx(); 14 ~CListCtrlEx(); 15 16 //void SetColor(const ColorTable& colors); 17 void GetItemSelected(vector<int>& item_selected) const; 18 int GetCurSel() const; //获取当前选中的项目 19 void SetCurSel(int select); 20 void SetCurSel(int first, int last); 21 void SetCurSel(const vector<int> indexes); 22 void SelectAll(); 23 void SelectNone(); 24 void SelectReverse(); 25 virtual bool SetRowHeight(int height, int left_space = 0); //设置表格行高,并同时设置需要在左侧额外增加的边距 SetHightItem(int item)26 void SetHightItem(int item) { m_highlight_item = item; } //设置高亮的项目(播放列表中正在播放的项目) 27 void SetDragEnable(bool enable = true) { m_drag_enable = enable; } //是否允许鼠标拖动 28 virtual void ShowPopupMenu(CMenu* pMenu, int item_index, CWnd* pWnd); 29 void FillLeftSpaceAfterPaint(bool fill); //如果为true,则在每行绘制之后填充左侧空白,否则在绘制之前填充(如果表格没有图标或复选框,则应设置为true,否则设置为false) 30 void SetMouseWheelEnable(bool enable); //设置是否允许响应鼠标滚轮 31 void SetItemIcon(int item, HICON icon); //为列表项指定图标。如果使用此函数设置了图标,则必须调用SetRowHeight函数通过left_space参数设置要为图标留出的宽度 32 virtual bool DeleteItem(int nItem); 33 34 typedef map<int, wstring> RowData; //列表数据中每一行的数据,map的key为列序号,value为显示的文本 35 typedef vector<RowData> ListData; //列表数据,其中vector为每一行的数据 36 37 //设置列表数据 38 //(注:使用此函数设置列表数据使用了虚拟列表的方式,可显著提升在数据量很多的情况下的加载速度, 39 //使用此函数时必须确保列表具有 LVS_OWNERDATA 样式) 40 void SetListData(ListData* pListData); 41 42 //设置列表数据 43 //(使用传统的方式) 44 void SetListData(const ListData& list_data); 45 SetCtrlAEnable(bool enable)46 void SetCtrlAEnable(bool enable) { m_enable_ctrl_a = enable; } //是否允许Ctrl + A全选 47 48 wstring GetAllText(const wchar_t* sperator = L"\t"); 49 50 protected: 51 const ColorTable& m_theme_color; 52 COLORREF m_background_color{ GRAY(255) }; //列表控件的背景色 53 int m_highlight_item{ -1 }; //高亮的项目 54 bool m_drag_enable{ false }; 55 bool m_dragging{ false }; 56 HCURSOR m_drag_cursor{}; 57 bool m_fill_left_space_after_paint{ true }; 58 ListData* m_pListData{}; 59 bool m_enable_ctrl_a{ false }; //是否允许Ctrl+A全选 60 int m_row_height{}; 61 bool m_mouse_wheel_enable{ true }; 62 std::map<int, HICON> m_icons; 63 64 public: 65 DECLARE_MESSAGE_MAP() 66 afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult); 67 virtual void PreSubclassWindow(); 68 afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 69 afx_msg void OnRButtonDown(UINT nFlags, CPoint point); 70 virtual BOOL PreTranslateMessage(MSG* pMsg); 71 afx_msg void OnSetFocus(CWnd* pOldWnd); 72 afx_msg void OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult); 73 afx_msg void OnLButtonUp(UINT nFlags, CPoint point); 74 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); 75 afx_msg BOOL OnEraseBkgnd(CDC* pDC); 76 afx_msg void OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult); 77 protected: 78 afx_msg LRESULT OnTabletQuerysystemgesturestatus(WPARAM wParam, LPARAM lParam); 79 }; 80 81