Better like this:
Code: Select all
Gui, Add, ListView, hwndhLV, Title
Gui, ListView, %hLV%
LV_Add(, "2019/08/13 07:01:52")
LV_Add(, "2019/8/13 1:54:50")
LV_Add(, "2019/8/14 20:31:43")
LV_Add(, "2019/8/9 23:41:52")
pSortItems := RegisterCallback("SortItems", "F")
info := {guiID: 1, lv: hLV, even: true, callback: pSortItems}
pInfo := Object(info)
eventHandler := Func("Events").Bind(pInfo)
GuiControl, +g, %hLV%, % eventHandler
SendMessage, LVM_SORTITEMSEX := 0x1051, pInfo, pSortItems,, ahk_id %hLV%
ObjRelease(pInfo)
Gui, Show
Return
GuiClose:
ExitApp
Events(pInfo) {
if (A_GuiEvent = "ColClick" && A_EventInfo = 1) {
info := Object(pInfo)
info.even := !info.even
SendMessage, LVM_SORTITEMSEX := 0x1051, pInfo, info.callback,, % "ahk_id" . info.lv
}
}
SortItems(a, b, pInfo) {
static pattern := "O)(\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+)"
info := Object(pInfo)
Gui, % info.guiID . ":ListView", % info.lv
LV_GetText(textA, a + 1)
LV_GetText(textB, b + 1)
if RegExMatch(textA, pattern, _a) && RegExMatch(textB, pattern, _b) {
Loop 6 {
if (_a[A_Index] != _b[A_Index])
Return _a[A_Index] > _b[A_Index] ? info.even*2 - 1 : 1 - info.even*2
}
Return 0
}
}