The HDN_FILTERCHANGE notification is sent via WM_NOTIFY. See here for details on the notification - https://docs.microsoft.com/en-us/windows/desktop/controls/hdn-filterchange
I can't seem to get things quite right with HDM_GETITEM to properly retrieve the filter text. Are my offsets correct? Am I looking for the string in the proper place?
EDIT: This AutoIt post could be of help but it sure seems like I'm doing the same thing - https://www.autoitscript.com/forum/topic/190357-filter-in-listview-header/
Code: Select all
main := GuiCreate()
lv := main.addListView("w400 h400", "col1|col2|col3")
; get hwnd of Header control
lvHeader := SendMessage(0x101F, 0, 0, , "ahk_id " . lv.hwnd)
; toggle the HDS_FILTERBAR style
WinSetStyle("^0x100", "ahk_id " lvHeader)
; populate ListView
Loop(100) {
lv.Add("", "Col 1 - Row " A_Index, "Col 2 - Row " A_Index, "Col 3 - Row " A_Index)
}
LV.ModifyCol()
lv.OnNotify(HDN_FILTERBTNCLICK := -313, "LV_OnNotify")
main.show()
return
LV_OnNotify(ctrl, lParam) {
static HDM_GETITEM := 0x120B
static NMHDR_Size := A_PtrSize * 3
static HDItemSize := (4 * 6) + (A_PtrSize * 6)
static typeOffset := 44
static pvFilterOffset := typeOffset + 4
hwnd := NumGet(lParam, 0, "Ptr")
col := NumGet(lParam, NMHDR_Size, "Int")
; String buffer for HDTEXTFILTER struct
VarSetCapacity(string, 64 * 2, 0)
; HDFILTER struct
VarSetCapacity(HDTEXTFILTER, A_PtrSize + 4)
NumPut(&string, HDTEXTFILTER, 0, "UPtr") ; add pointer to string buffer variable
NumPut(64*2, HDTEXTFILTER, 8, "Int") ; buffer size
; HDITEM struct
VarSetCapacity(HDItem, HDItemSize)
NumPut(0x100, HDItem, 0, "UInt") ; Set the Mask to HDI_FILTER := 0x100
NumPut(0x0, HDItem, typeOffset, "UInt") ; Set the Type to HDFT_ISSTRING := 0x0
NumPut(&HDTEXTFILTER, HDItem, pvFilterOffset, "Ptr") ; Add pointer to HDTEXTFILTER struct
; Send message to get the item
SendMessage(HDM_GETITEM, col, &HDItem, , "ahk_id " hwnd)
; Assume that the filter text should then be contained in the variable 'string', no?
ToolTip("Column index - " col "`n`nfilter = " string)
}