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-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;
}
1