chrisser Posted February 9, 2016 Share Posted February 9, 2016 Hi, i hope someone can help me. I try to get the filtertext from the header of a Listview. I have no idea to handle the "$tagHDTEXTFILTER" from the "GUI_Header.au3". Here is an example, found here some years ago. I can´t find the post again. Thanks, chrisser expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> #include <WinAPI.au3> $gui = GUICreate("listview filter", 400, 250, -1, -1) $listview = GUICtrlCreateListView("col0|col1|col2", 10, 10, 380, 230) GUICtrlSendMsg(-1, 0x101E, 0, 125) GUICtrlSendMsg(-1, 0x101E, 1, 125) GUICtrlSendMsg(-1, 0x101E, 2, 125) GUICtrlCreateListViewItem("blue|green|blue", $listview) GUICtrlCreateListViewItem("red|blue|green", $listview) GUICtrlCreateListViewItem("green|red|red", $listview) GUICtrlCreateListViewItem("blue|green|blue", $listview) GUICtrlCreateListViewItem("red|blue|green", $listview) GUICtrlCreateListViewItem("green|red|red", $listview) GUICtrlCreateListViewItem("blue|green|blue", $listview) GUICtrlCreateListViewItem("red|blue|green", $listview) GUICtrlCreateListViewItem("green|red|red", $listview) GUICtrlCreateListViewItem("blue|green|blue", $listview) GUICtrlCreateListViewItem("red|blue|green", $listview) GUICtrlCreateListViewItem("green|red|red", $listview) GUISetState() ;Use of lock/unlock and begin/end update is just to cause repainting so the filterbar is fully visible GUISetState(@SW_LOCK, $gui) _GUICtrlListView_BeginUpdate($listview) ;Add the filter bar to the header control $header = _GUICtrlListView_GetHeader($listview) $styles = _WinAPI_GetWindowLong($header, $GWL_STYLE) _WinAPI_SetWindowLong($header, $GWL_STYLE, BitOR($styles, $HDS_FILTERBAR)) ;Use of lock/unlock and begin/end update is just to cause repainting so the filterbar is fully visible _GUICtrlListView_EndUpdate($listview) GUISetState(@SW_UNLOCK, $gui) _GUICtrlHeader_EditFilter($header, 0) Send("Filter 1") ;Register WM_NOTIFY to handle $HDN_FILTERBTNCLICK messages GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Sleep(1000) MsgBox(0,"",_GUICtrlHeader_GetFilterText($header, 0)) ;Loop GUI until exit Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode Local $tNMHDR, $tNMHEADER, $tNMHDFILTERBTNCLICK, $tHDTEXTFILTER, $tNMHDDISPINFO Local $iHeaderItem, $tItem Local $HDFT_ISSTRING = 0x0 Local $HDFT_ISNUMBER = 0x1 $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $header Switch $iCode Case $HDN_FILTERBTNCLICK ; Notifies the header control's parent window when the filter button is clicked or in response to an $HDM_SETITEM message $tNMHDFILTERBTNCLICK = DllStructCreate($tagNMHDFILTERBTNCLICK, $ilParam) $tHDTEXTFILTER = DllStructCreate($tagHDTEXTFILTER, $ilParam) $column = DllStructGetData($tNMHDFILTERBTNCLICK, "Item") $text = DllStructGetData($tHDTEXTFILTER, "Text") MsgBox(0, "Msg", "Filter button click for column " & $column & @CRLF & _ "Text: " & $text) ;Return True ; An $HDN_FILTERCHANGE notification will be sent to the header control's parent window ; This notification gives the parent window an opportunity to synchronize its user interface elements Return False ; If you do not want the notification sent Case $HDN_FILTERCHANGE ; Notifies the header control's parent window that the attributes of a header control filter are being changed or edited ;$tNMHEADER = DllStructCreate($tagNMHEADER, $ilParam) ; no return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _GUICtrlHeader_GetFilterText($hWnd, $iIndex) Local $bUnicode = _GUICtrlHeader_GetUnicodeFormat($hWnd) Local $tBuffer If $bUnicode Then $tBuffer = DllStructCreate("wchar Text[4096]") Else $tBuffer = DllStructCreate("char Text[4096]") EndIf Local $tItem = DllStructCreate($tagHDTEXTFILTER) DllStructSetData($tItem, "TextMax", 4096) If _WinAPI_InProcess($hWnd, $__g_hHDRLastWnd) Then DllStructSetData($tItem, "Text", DllStructGetPtr($tBuffer)) _SendMessage($hWnd, $HDM_GETITEMW, $iIndex, $tItem, 0, "wparam", "struct*") Else Local $iItem = DllStructGetSize($tItem) Local $tMemMap Local $pMemory = _MemInit($hWnd, $iItem + DllStructGetSize($tBuffer), $tMemMap) Local $pText = $pMemory + $iItem DllStructSetData($tItem, "Text", $pText) _MemWrite($tMemMap, $tItem, $pMemory, $iItem) If $bUnicode Then _SendMessage($hWnd, $HDM_GETITEMW, $iIndex, $pMemory, 0, "wparam", "ptr") Else _SendMessage($hWnd, $HDM_GETITEMA, $iIndex, $pMemory, 0, "wparam", "ptr") EndIf _MemRead($tMemMap, $pText, $tBuffer, DllStructGetSize($tBuffer)) _MemFree($tMemMap) EndIf Return DllStructGetData($tBuffer, "Text") EndFunc ;==>_GUICtrlHeader_GetItemText Link to comment Share on other sites More sharing options...
LarsJ Posted February 10, 2016 Share Posted February 10, 2016 Here you are: expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> #include <WinAPI.au3> $gui = GUICreate("listview filter", 400, 250, -1, -1) $listview = GUICtrlCreateListView("col0|col1|col2", 10, 10, 380, 230) GUICtrlSendMsg(-1, 0x101E, 0, 125) GUICtrlSendMsg(-1, 0x101E, 1, 125) GUICtrlSendMsg(-1, 0x101E, 2, 125) GUICtrlCreateListViewItem("blue|green|blue", $listview) GUICtrlCreateListViewItem("red|blue|green", $listview) GUICtrlCreateListViewItem("green|red|red", $listview) GUICtrlCreateListViewItem("blue|green|blue", $listview) GUICtrlCreateListViewItem("red|blue|green", $listview) GUICtrlCreateListViewItem("green|red|red", $listview) GUICtrlCreateListViewItem("blue|green|blue", $listview) GUICtrlCreateListViewItem("red|blue|green", $listview) GUICtrlCreateListViewItem("green|red|red", $listview) GUICtrlCreateListViewItem("blue|green|blue", $listview) GUICtrlCreateListViewItem("red|blue|green", $listview) GUICtrlCreateListViewItem("green|red|red", $listview) GUISetState() ;Use of lock/unlock and begin/end update is just to cause repainting so the filterbar is fully visible GUISetState(@SW_LOCK, $gui) _GUICtrlListView_BeginUpdate($listview) ;Add the filter bar to the header control $header = _GUICtrlListView_GetHeader($listview) $styles = _WinAPI_GetWindowLong($header, $GWL_STYLE) _WinAPI_SetWindowLong($header, $GWL_STYLE, BitOR($styles, $HDS_FILTERBAR)) ;Use of lock/unlock and begin/end update is just to cause repainting so the filterbar is fully visible _GUICtrlListView_EndUpdate($listview) GUISetState(@SW_UNLOCK, $gui) _GUICtrlHeader_EditFilter($header, 0) Send("Filter 1") ;Register WM_NOTIFY to handle $HDN_FILTERBTNCLICK messages GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;Loop GUI until exit Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode Local $tNMHDR, $tNMHEADER, $tNMHDFILTERBTNCLICK, $tHDTEXTFILTER, $tNMHDDISPINFO Local $iHeaderItem, $tItem Local $HDFT_ISSTRING = 0x0 Local $HDFT_ISNUMBER = 0x1 $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $header Switch $iCode Case $HDN_FILTERBTNCLICK ; Notifies the header control's parent window when the filter button is clicked or in response to an $HDM_SETITEM message $tNMHDFILTERBTNCLICK = DllStructCreate($tagNMHDFILTERBTNCLICK, $ilParam) $column = DllStructGetData($tNMHDFILTERBTNCLICK, "Item") $tText = DllStructCreate( "wchar[64]" ) $pText = DllStructGetPtr( $tText ) $tHDTEXTFILTER = DllStructCreate( $tagHDTEXTFILTER ) $pHDTEXTFILTER = DllStructGetPtr( $tHDTEXTFILTER ) DllStructSetData( $tHDTEXTFILTER, "Text", $pText ) DllStructSetData( $tHDTEXTFILTER, "TextMax", 64 ) $tHDITEM = DllStructCreate( $tagHDITEM ) DllStructSetData( $tHDITEM, "Mask", $HDI_FILTER ) DllStructSetData( $tHDITEM, "Type", 0 ) DllStructSetData( $tHDITEM, "pFilter", $pHDTEXTFILTER ) $pHDITEM = DllStructGetPtr( $tHDITEM ) _SendMessage( $header, $HDM_GETITEMW, $column, $pHDITEM ) $sText = DllStructGetData( $tText, 1 ) MsgBox(0, "Msg", "Filter button click for column " & $column & @CRLF & _ "Text: " & $sText) ;Return True ; An $HDN_FILTERCHANGE notification will be sent to the header control's parent window ; This notification gives the parent window an opportunity to synchronize its user interface elements Return False ; If you do not want the notification sent Case $HDN_FILTERCHANGE ; Notifies the header control's parent window that the attributes of a header control filter are being changed or edited ;$tNMHEADER = DllStructCreate($tagNMHEADER, $ilParam) ; no return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Nice filters. I've never used filters before. It seems as if you have to do everything manually. If you type a filter text you have to manually update the rows in the listview to reflect the filter. pixelsearch 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
chrisser Posted February 10, 2016 Author Share Posted February 10, 2016 Wow! Thank you so much Lars!!! I almost get no sleep because of this last night ;D I think those filters can be very practically in bigger listviews. I can build a new (My)SQL- Select from this information and rebuild the listview. So for that case it´s easy to go on. And now i understand how the DLL-Functions are working! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now