Gui, Add, Listview, x0 y0 h200 w400 hwndhLV, Title1|Title2
header := SetHeaderItemCheckBox(hLV, 1)
OnMessage(0x4E, Func("WM_NOTIFY").Bind(header, 1))
Gui, Show, h200 w400
Loop 2 {
LV_Add(, 111, 222)
LV_ModifyCol(A_Index, "autohdr")
}
return
GuiClose() {
ExitApp
}
SetHeaderItemCheckBox(hListView, item) {
static LVM_GETHEADER := 0x101F, HDS_CHECKBOXES := 0x400, HDI_FORMAT := 0x4
, HDM_FIRST := 0x1200, HDM_GETITEM := HDM_FIRST + (A_IsUnicode ? 3 : 11)
, HDM_SETITEM := HDM_GETITEM + 1, HDF_CHECKBOX := 0x40
, HDITEM_SIZE := 4*6 + A_PtrSize*6, fmt_offset := 4*3 + A_PtrSize*2
SendMessage, LVM_GETHEADER,,,, ahk_id %hListView%
WinExist("ahk_id" header := ErrorLevel)
WinSet, Style, +%HDS_CHECKBOXES%
VarSetCapacity(HDITEM, HDITEM_SIZE, 0)
NumPut(HDI_FORMAT, HDITEM)
SendMessage, HDM_GETITEM, --item, &HDITEM
fmt := NumGet(HDITEM, fmt_offset, "Int")
NumPut(fmt|HDF_CHECKBOX, HDITEM, fmt_offset)
SendMessage, HDM_SETITEM, item, &HDITEM
Return header
}
WM_NOTIFY(header, item, wp, lp) {
static HDN_ITEMSTATEICONCLICK := -16, HDI_FORMAT := 0x4, HDF_CHECKED := 0x80
, HDM_FIRST := 0x1200, HDM_GETITEM := HDM_FIRST + (A_IsUnicode ? 3 : 11)
, HDITEM_SIZE := 4*6 + A_PtrSize*6, fmt_offset := 4*3 + A_PtrSize*2
, prevChecked := 0
if NumGet(lp+0) = header && NumGet(lp + A_PtrSize*2, "Int") = HDN_ITEMSTATEICONCLICK {
VarSetCapacity(HDITEM, HDITEM_SIZE, 0)
NumPut(HDI_FORMAT, HDITEM)
SendMessage, HDM_GETITEM, --item, &HDITEM,, ahk_id %header%
checked := NumGet(HDITEM, fmt_offset, "Int") & HDF_CHECKED
if (checked != prevChecked) {
prevChecked := checked
ToolTip, % "Header's checkbox is " . (checked ? "" : "un") . "checked"
}
}
}