文件名称:CListCtrl 拖拽功能移动选中行的位置
文件大小:4KB
文件格式:RAR
更新时间:2022-02-05 04:03:48
CListCtrl
CDragListCtrl继承CListCtrl类,CDragListCtrl实现拖动时绘制该行的内容浮动在鼠标移动的位置。CDragList主要用于计算当前鼠标移动到那一行上。 使用CDragListCtrl的对话框添加 afx_msg LRESULT DragMoveItem(WPARAM wParam, LPARAM lParam); ON_MESSAGE(WM_MOVEITEM, DragMoveItem) LRESULT DialUploadLoopTask::DragMoveItem(WPARAM wParam, LPARAM lParam) { int iSelectItem = wParam; int iChangeItem = lParam; if (iSelectItem == -1 || iChangeItem == -1) { return 0; } CString strTaskName = m_CListCtrlTask.GetItemText(iSelectItem, 0); CString strTaskID = m_CListCtrlTask.GetItemText(iSelectItem, 1); CString strTaskSynStatus = m_CListCtrlTask.GetItemText(iSelectItem, 2); if (iSelectItem < iChangeItem) { for (int i = iSelectItem; i <= iChangeItem; i++) { if (i == iChangeItem) { m_CListCtrlTask.SetItemText(iChangeItem, 0, strTaskName); m_CListCtrlTask.SetItemText(iChangeItem, 1, strTaskID); m_CListCtrlTask.SetItemText(iChangeItem, 2, strTaskSynStatus); } else { m_CListCtrlTask.SetItemText(i, 0, m_CListCtrlTask.GetItemText(i + 1, 0)); m_CListCtrlTask.SetItemText(i, 1, m_CListCtrlTask.GetItemText(i + 1, 1)); m_CListCtrlTask.SetItemText(i, 2, m_CListCtrlTask.GetItemText(i + 1, 2)); } } } else { for (int i = iSelectItem; i > iChangeItem; i--) { if (i-1 == iChangeItem) { m_CListCtrlTask.SetItemText(i, 0, strTaskName); m_CListCtrlTask.SetItemText(i, 1, strTaskID); m_CListCtrlTask.SetItemText(i, 2, strTaskSynStatus); } else { m_CListCtrlTask.SetItemText(i, 0, m_CListCtrlTask.GetItemText(i - 1, 0)); m_CListCtrlTask.SetItemText(i, 1, m_CListCtrlTask.GetItemText(i - 1, 1)); m_CListCtrlTask.SetItemText(i, 2, m_CListCtrlTask.GetItemText(i - 1, 2)); } } } return 0; }
【文件预览】:
ctrl
----DragList.h(750B)
----DragList.cpp(6KB)
----CDragListCtrl.cpp(6KB)
----CDragListCtrl.h(775B)