#include <GuiListView.au3>
#include <WindowsConstants.au3>
$hGui = GuiCreate("Test", 400, 300)
$lvExStyle = bitOr($lvs_ex_fullrowselect, $lvs_ex_gridlines, _
$lvs_ex_doublebuffer, $ws_ex_clientedge)
Global $iFlag = False
$lv = GuiCtrlCreateListView("Test|Drag", 5, 5, 390, 280, $lvs_report, $lvExStyle)
For $o = 1 to 10
$Item = "Item " & $o & "|Sub Item " & $o & " - 1"
GuiCtrlCreateListViewItem($Item, $lv)
Next
GuiSetState()
GuiRegisterMsg($wm_notify, "_wmNotify")
Do
Until GuiGetMsg() = -3
Func _WmNotify($hWnd, $iMsg, $wParam, $lParam)
Local $tNmhdr, $iCode
$tNmhdr = DllStructCreate($tagNmhdr, $lParam)
$iCode = DllStructGetData($tNmhdr, "code")
If $wParam = $lv Then
Switch $iCode
Case $lvn_beginDrag
$iFlag = True
Case $lvn_hotTrack
If not $iFlag Then Return False
$iFlag = False
_DragItems()
EndSwitch
EndIf
$tNmhdr = 0
EndFunc ;==>_WmNotify()
Func _DragItems()
Local $selection = _GuiCtrlListView_GetSelectedIndices($lv, true)
If $selection[0] = 0 then Return False
Local $selectionText[Ubound($selection) + 1][2]
For $d = 0 to $selection[0] - 1
For $x = 0 to 1
$selectionText[$d][$x] = _GuiCtrlListView_GetItemText($lv, $selection[$d+1], $x)
Next
Next
_GuiCtrlListView_DeleteItemsSelected(GuiCtrlGetHandle($lv))
Local $cursor = GuiGetCursorInfo($hGui)
Local $lvsPos = ControlGetPos($hGui, "", $lv)
$lvsPos[0] = $cursor[0] - $lvsPos[0]
$lvsPos[1] = $cursor[1] - $lvsPos[1]
$InsertPos = _GuiCtrlListView_HitTest($lv, $lvsPos[0], $lvsPos[1])
If $InsertPos[0] = -1 then $InsertPos[0] = _GuiCtrlListView_GetItemCount($lv)
For $d = $selection[0] - 1 to 0 step - 1
_GuiCtrlListView_InsertItem($lv, $selectionText[$d][0], $InsertPos[0], 0)
_GuiCtrlListView_AddSubItem($lv, $InsertPos[0], $selectionText[$d][1], 1,1)
Next
EndFunc ;==>_DragItems()
[ 本帖最后由 pusofalse 于 2009-3-20 20:51 编辑 ] |