该函数来自AHK 官方论坛,
函数比较短小强悍,支持多行同时移动。函数关键点都有注释,虽然是洋文,但勉强应该看得懂
PS:我自己也写过类似函数,但貌似这个函数更简洁优美,记录下来,随时翻阅。
1 Gui, Add, Listview, w260 h200 vmylistview, test|test2|test3|test4 2 LV_Modifycol(1, 60) 3 LV_Modifycol(2, 60) 4 LV_Modifycol(3, 60) 5 LV_Modifycol(4, 60) 6 7 Loop, 10 8 LV_Add("", A_Index, "-" A_Index, (10 - A_Index), "x" A_Index) 9 10 Gui, Show, Center AutoSize, TestGUI11 Return12 13 GuiClose:14 GuiEscape:15 ExitApp16 17 PgUp::LV_MoveRow()18 PgDn::LV_MoveRow(false)19 20 LV_MoveRow(moveup = true) {21 ; Original by diebagger (Guest) from:22 ; http://de.autohotkey.com/forum/viewtopic.php?p=58526#5852623 ; Slightly Modifyed by Obi-Wahn24 If moveup not in 1,025 Return ; If direction not up or down (true or false)26 while x := LV_GetNext(x) ; Get selected lines27 i := A_Index, i%i% := x28 If (!i) || ((i1 < 2) && moveup) || ((i%i% = LV_GetCount()) && !moveup)29 Return ; Break Function if: nothing selected, (first selected < 2 AND moveup = true) [header bug]30 ; OR (last selected = LV_GetCount() AND moveup = false) [delete bug]31 cc := LV_GetCount("Col"), fr := LV_GetNext(0, "Focused"), d := moveup ? -1 : 132 ; Count Columns, Query Line Number of next selected, set direction math.33 Loop, %i% { ; Loop selected lines34 r := moveup ? A_Index : i - A_Index + 1, ro := i%r%, rn := ro + d35 ; Calculate row up or down, ro (current row), rn (target row)36 Loop, %cc% { ; Loop through header count37 LV_GetText(to, ro, A_Index), LV_GetText(tn, rn, A_Index)38 ; Query Text from Current and Targetrow39 LV_Modify(rn, "Col" A_Index, to), LV_Modify(ro, "Col" A_Index, tn)40 ; Modify Rows (switch text)41 }42 LV_Modify(ro, "-select -focus"), LV_Modify(rn, "select vis")43 If (ro = fr)44 LV_Modify(rn, "Focus")45 }46 }