-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathLV_SortArrow.ahk
29 lines (29 loc) · 1.42 KB
/
LV_SortArrow.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
; LV_SortArrow by Solar. http://www.autohotkey.com/forum/viewtopic.php?t=69642
; h = ListView handle
; c = 1 based index of the column
; d = Optional direction to set the arrow. "asc" or "up". "desc" or "down".
LV_SortArrow(h, c, d="") {
static ptr, ptrSize, lvColumn, LVM_GETCOLUMN, LVM_SETCOLUMN
if (!ptr)
ptr := A_PtrSize ? ("ptr", ptrSize := A_PtrSize) : ("uint", ptrSize := 4)
,LVM_GETCOLUMN := A_IsUnicode ? (4191, LVM_SETCOLUMN := 4192) : (4121, LVM_SETCOLUMN := 4122)
,VarSetCapacity(lvColumn, ptrSize + 4), NumPut(1, lvColumn, "uint")
c -= 1, DllCall("SendMessage", ptr, h, "uint", LVM_GETCOLUMN, "uint", c, ptr, &lvColumn)
if ((fmt := NumGet(lvColumn, 4, "int")) & 1024) {
if (d && d = "asc" || d = "up")
return
NumPut(fmt & ~1024 | 512, lvColumn, 4, "int")
} else if (fmt & 512) {
if (d && d = "desc" || d = "down")
return
NumPut(fmt & ~512 | 1024, lvColumn, 4, "int")
} else {
Loop % DllCall("SendMessage", ptr, DllCall("SendMessage", ptr, h, "uint", 4127), "uint", 4608)
if ((i := A_Index - 1) != c)
DllCall("SendMessage", ptr, h, "uint", LVM_GETCOLUMN, "uint", i, ptr, &lvColumn)
,NumPut(NumGet(lvColumn, 4, "int") & ~1536, lvColumn, 4, "int")
,DllCall("SendMessage", ptr, h, "uint", LVM_SETCOLUMN, "uint", i, ptr, &lvColumn)
NumPut(fmt | (d && d = "desc" || d = "down" ? 512 : 1024), lvColumn, 4, "int")
}
return DllCall("SendMessage", ptr, h, "uint", LVM_SETCOLUMN, "uint", c, ptr, &lvColumn)
}