It's nice,but if the listview have icons,now it can't move the icon synchronous,here is a example of listview,I suggest improve your script so that the icon can be moved at the same time
Gui +Resize
Gui, Add, Button, Default gButtonLoadFolder, Load a folder
Gui, Add, Button, x+20 gButtonClear, Clear List
Gui, Add, Button, x+20, Switch View
Gui, Add, ListView, xm r20 w700 vMyListView gMyListView, Name|In Folder|Size (KB)|Type
LV_ModifyCol(3, "Integer") ;
ImageListID1 := IL_Create(10)
ImageListID2 := IL_Create(10, 10, true) ; A list of large icons to go with the small ones.
LV_SetImageList(ImageListID1)
LV_SetImageList(ImageListID2)
Menu, MyContextMenu, Add, Open, ContextOpenFile
Menu, MyContextMenu, Add, Properties, ContextProperties
Menu, MyContextMenu, Add, Clear from ListView, ContextClearRows
Menu, MyContextMenu, Default, Open
Gui, Show
return
ButtonLoadFolder:
Gui +OwnDialogs
FileSelectFolder, Folder,, 3, Select a folder to read:
if not Folder
return
StringRight, LastChar, Folder, 1
if LastChar = \
StringTrimRight, Folder, Folder, 1
VarSetCapacity(Filename, 260)
sfi_size = 352
VarSetCapacity(sfi, sfi_size)
GuiControl, -Redraw, MyListView
Loop %Folder%\*.*
{
FileName := A_LoopFileFullPath
SplitPath, FileName,,, FileExt
if FileExt in EXE,ICO,ANI,CUR
{
ExtID := FileExt
IconNumber = 0
}
else
{
ExtID = 0
Loop 7
{
StringMid, ExtChar, FileExt, A_Index, 1
if not ExtChar
break
ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1)))
}
IconNumber := IconArray%ExtID%
}
if not IconNumber
{
if not DllCall("Shell32\SHGetFileInfoA", "str", FileName, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101) ; 0x101 是 SHGFI_ICON+SHGFI_SMALLICON
IconNumber = 9999999
else
{
; Extract the hIcon member from the structure:
hIcon = 0
Loop 4
hIcon += *(&sfi + A_Index-1) << 8*(A_Index-1)
; Add the HICON directly to the small-icon and large-icon lists.
; Below uses +1 to convert the returned index from zero-based to one-based:
IconNumber := DllCall("ImageList_ReplaceIcon", "uint", ImageListID1, "int", -1, "uint", hIcon) + 1
DllCall("ImageList_ReplaceIcon", "uint", ImageListID2, "int", -1, "uint", hIcon)
; Now that it's been copied into the ImageLists, the original should be destroyed:
DllCall("DestroyIcon", "uint", hIcon)
; Cache the icon to save memory and improve loading performance:
IconArray%ExtID% := IconNumber
}
}
; Create the new row in the ListView and assign it the icon number determined above:
LV_Add("Icon" . IconNumber, A_LoopFileName, A_LoopFileDir, A_LoopFileSizeKB, FileExt)
}
GuiControl, +Redraw, MyListView
LV_ModifyCol()
LV_ModifyCol(3, 60)
return
ButtonClear:
LV_Delete()
return
ButtonSwitchView:
if not IconView
GuiControl, +Icon, MyListView
else
GuiControl, +Report, MyListView
IconView := not IconView
return
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(FileName, A_EventInfo, 1)
LV_GetText(FileDir, A_EventInfo, 2)
Run %FileDir%\%FileName%,, UseErrorLevel
if ErrorLevel
MsgBox Could not open "%FileDir%\%FileName%".
}
return
GuiContextMenu:
if A_GuiControl <> MyListView
return
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return
ContextOpenFile:
ContextProperties:
FocusedRowNumber := LV_GetNext(0, "F")
if not FocusedRowNumber
return
LV_GetText(FileName, FocusedRowNumber, 1)
LV_GetText(FileDir, FocusedRowNumber, 2)
IfInString A_ThisMenuItem, Open
Run %FileDir%\%FileName%,, UseErrorLevel
else
Run Properties "%FileDir%\%FileName%",, UseErrorLevel
if ErrorLevel
MsgBox Could not perform requested action on "%FileDir%\%FileName%".
return
ContextClearRows:
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
if not RowNumber
break
LV_Delete(RowNumber)
}
return
GuiSize:
if A_EventInfo = 1
return
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40)
return
GuiClose:
ExitApp
PgUp::LV_MoveRow()
PgDn::LV_MoveRow(false)
LV_MoveRow(moveup = true) {
; Original by diebagger (Guest) from:
; http://de.autohotkey.com/forum/viewtopic.php?p=58526#58526
; Slightly Modifyed by Obi-Wahn
If moveup not in 1,0
Return ; If direction not up or down (true or false)
while x := LV_GetNext(x) ; Get selected lines
i := A_Index, i%i% := x
If (!i) || ((i1 < 2) && moveup) || ((i%i% = LV_GetCount()) && !moveup)
Return ; Break Function if: nothing selected, (first selected < 2 AND moveup = true) [header bug]
; OR (last selected = LV_GetCount() AND moveup = false) [delete bug]
cc := LV_GetCount("Col"), fr := LV_GetNext(0, "Focused"), d := moveup ? -1 : 1
; Count Columns, Query Line Number of next selected, set direction math.
Loop, %i% { ; Loop selected lines
r := moveup ? A_Index : i - A_Index + 1, ro := i%r%, rn := ro + d
; Calculate row up or down, ro (current row), rn (target row)
Loop, %cc% { ; Loop through header count
LV_GetText(to, ro, A_Index), LV_GetText(tn, rn, A_Index)
; Query Text from Current and Targetrow
LV_Modify(rn, "Col" A_Index, to), LV_Modify(ro, "Col" A_Index, tn)
; Modify Rows (switch text)
}
LV_Modify(ro, "-select -focus"), LV_Modify(rn, "select vis")
If (ro = fr)
;gosub,icon
LV_Modify(rn, "Focus")
;LV_Modify("Icon" . IconNumber,rn)
}
}