Hello,
Here is a example to add a filterbar into a listicon header and search wirth the string of the filterbar.
Please go to this link
FilterBar ListiconGadget Example
Code: Select all
;ListIcon Filter example
;by nicolaus in the german and english PureBasic board
; 10.06.2006
;..............................
;in this example you see in the header of the listicon a filterbar.
;in this bar you can type a string and after 3 secs the filter will search the string in
;the listicon items. after you type a string in the filterbar you can also click the button at the
;right side of the filterbar.
;after click the button or wait 3 secs the function "SearchInLI()" will search the string in the listicon
;and select it if the string is found.
;
;hope you like it.
;
;regards nico
#LVM_FIRST = $1000
#HDM_LAYOUT = (#HDM_FIRST+5)
#LVM_GETHEADER = (#LVM_FIRST+31)
#HDS_BUTTONS = $0002
#HDS_FLAT = $0200
#HDS_FILTERBAR = $0100
#HDN_FILTERBTNCLICK = (#HDN_FIRST-13)
#HDN_FILTERCHANGE = (#HDN_FIRST-12)
#LVM_SETEXTENDEDLISTVIEWSTYLE = (#LVM_FIRST+54)
#LVS_EX_FLATSB = $100
#LVS_EX_HEADERDRAGDROP = $00000010
#LVS_EX_FULLROWSELECT = $00000020
#HDI_FILTER = $0100
#HDFT_ISSTRING = $0000
#HDM_SETFILTERCHANGETIMEOUT = (#HDM_FIRST+22)
Global oldproc, newheight, hListIcon, hHeader
;
; Structure HDITEM
; mask
; cxy
; pszText
; hbm
; cchTextMax
; fmt
; lParam
; iImage
; iOrder
; type
; pvFilter
; EndStructure
Structure HDTEXTFILTER Align #PB_Structure_AlignC
*pszText
cchTextMax.l
EndStructure
Procedure SearchInLI(gadget.l,String.s) ; search in the listicon for the givend string
SendMessage_(GadgetID(gadget), #LVM_FIRST + $54, $8, 1)
fItem.LV_FINDINFO
fItem\flags = #LVFI_STRING
fItem\psz = @String
itemNumber = SendMessage_(GadgetID(gadget), #LVM_FINDITEM, -1, fItem) ; find Item
If itemNumber > -1
Goto SCROLL_AND_SELECT
Else
For I = 0 To CountGadgetItems(gadget) - 1
If String = GetGadgetItemText(gadget, I, 1)
itemNumber = I
Goto SCROLL_AND_SELECT
EndIf
Next
EndIf
Goto PROC_ERROR
SCROLL_AND_SELECT:
pItem.POINT
SendMessage_(GadgetID(gadget), #LVM_GETITEMPOSITION, itemNumber , pItem) ; get item position
SendMessage_(GadgetID(gadget), #LVM_SCROLL, pItem\x, pItem\y - 150) ; scroll to item position
sItem.LV_ITEM
sItem\mask = #LVIF_STATE
sItem\state = #LVIS_SELECTED
sItem\stateMask = #LVIS_SELECTED
SendMessage_(GadgetID(gadget), #LVM_SETITEMSTATE, itemNumber , sItem) ; set item state as selected
Goto PROC_END
PROC_ERROR:
MessageRequester("Error", "Can´t finde'" + String + "' in the list", #MB_ICONEXCLAMATION | #MB_OK)
PROC_END:
EndProcedure
Procedure.l WinProc(hwnd.l, msg.l, wParam.l, lParam.l)
Result.l = 0
If msg = #HDM_LAYOUT
Result = CallWindowProc_(oldproc, hwnd, msg, wParam, lParam)
*hdlayout.HD_LAYOUT = lParam
If *hdlayout\prc <> 0
*rect.RECT = *hdlayout\prc
*rect\Top = newheight
EndIf
If *hdlayout\pwpos <> 0
*windowpos.WINDOWPOS = *hdlayout\pwpos
*windowpos\cy = newheight
EndIf
Else
Result = CallWindowProc_(oldproc, hwnd, msg, wParam, lParam)
EndIf
ProcedureReturn Result
EndProcedure
Procedure CallBack(hwnd.l, msg.l, wParam.l, lParam.l)
Result = #PB_ProcessPureBasicEvents
hHDItem.HDITEM
TFilter.HDTEXTFILTER
If msg = #WM_NOTIFY
*pNMHdr.NMHEADER = lParam
If *pNMHdr\hdr\code = #HDN_FILTERCHANGE
TFilter\pszText = AllocateMemory(256)
TFilter\cchTextMax = 256
hHDItem\mask = #HDI_FILTER
hHDItem\type = #HDFT_ISSTRING
hHDItem\pvFilter = @TFilter
SendMessage_(hHeader,#HDM_GETITEM,*pNMHdr\iItem,@hHDItem)
SearchInLI(1,PeekS(TFilter\pszText,256))
ElseIf *pNMHdr\hdr\code = #HDN_FILTERBTNCLICK
TFilter\pszText = AllocateMemory(256)
TFilter\cchTextMax = 256
hHDItem\mask = #HDI_FILTER
hHDItem\type = #HDFT_ISSTRING
hHDItem\pvFilter = @TFilter
SendMessage_(hHeader,#HDM_GETITEM,*pNMHdr\iItem,@hHDItem)
SearchInLI(1,PeekS(TFilter\pszText,256))
EndIf
EndIf
ProcedureReturn Result
EndProcedure
OpenWindow(0,0,0,400,200,"ListIcon-FilterTest",#PB_Window_SystemMenu)
hListIcon = ListIconGadget(1,0,0,400,195,"Name",200,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
; next we set the ext-style of the listicon
SendMessage_(hListIcon,#LVM_SETEXTENDEDLISTVIEWSTYLE,#LVS_EX_FLATSB|#LVS_EX_HEADERDRAGDROP,#LVS_EX_FLATSB|#LVS_EX_HEADERDRAGDROP)
; now we look for the handle of the listicon header....
hHeader = SendMessage_(hListIcon,#LVM_GETHEADER,0,0)
; and look for the winproc of the header
oldproc = SetWindowLong_(hHeader, #GWL_WNDPROC, @WinProc())
newheight = 35
; we set a new height of the listicon header so that we can set the filterbar into the header
SetWindowPos_(hHeader, 0, 0, 0, GadgetWidth(1), newheight, #SWP_NOZORDER | #SWP_NOMOVE)
hdItem.HDITEM
hdItem\mask = #HDI_FILTER
hdItem\type = #HDFT_ISSTRING
; now we set the timeout for the retur of the filter
SendMessage_(hHeader,#HDM_SETFILTERCHANGETIMEOUT, 0, 3000)
; we retrieves the actuall style of the listicon header....
lStyle = GetWindowLong_(hHeader,#GWL_STYLE)
; and add the style #HDS_FILTERBAR to the retrievet style
lStyle = lStyle | #HDS_FILTERBAR
; ok we set the new style to the listicon header
SetWindowLong_(hHeader,#GWL_STYLE, lStyle)
AddGadgetColumn(1,1,"City",180)
SetWindowCallback(@CallBack())
AddGadgetItem(1, -1, "Andreas" +Chr(10)+ "New York")
AddGadgetItem(1, -1, "Martin" +Chr(10)+ "Suhl")
AddGadgetItem(1, -1, "Fred" +Chr(10)+ "Paris")
AddGadgetItem(1, -1, "Andre" +Chr(10)+ "Erfurt")
AddGadgetItem(1, -1, "Rene" +Chr(10)+ "Leipzig")
AddGadgetItem(1, -1, "Sven" +Chr(10)+ "Emden")
AddGadgetItem(1, -1, "Mischael" +Chr(10)+ "Dresden")
AddGadgetItem(1, -1, "Marc" +Chr(10)+ "Rom")
AddGadgetItem(1, -1, "Nico" +Chr(10)+ "Bern")
AddGadgetItem(1, -1, "Karsten" +Chr(10)+ "Wien")
AddGadgetItem(1, -1, "Thomas" +Chr(10)+ "Hamburg")
AddGadgetItem(1, -1, "Bill" +Chr(10)+ "Gera")
AddGadgetItem(1, -1, "John" +Chr(10)+ "Tokyo")
AddGadgetItem(1, -1, "Elke" +Chr(10)+ "Miami")
AddGadgetItem(1, -1, "Sandra" +Chr(10)+ "Moskau")
AddGadgetItem(1, -1, "Sina" +Chr(10)+ "Jena")
AddGadgetItem(1, -1, "Liesa" +Chr(10)+ "Berlin")
AddGadgetItem(1, -1, "Laura" +Chr(10)+ "Lobenstein")
AddGadgetItem(1, -1, "Terry" +Chr(10)+ "Las Vegas")
AddGadgetItem(1, -1, "Dave" +Chr(10)+ "London")
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
regards,
nico