Code: Select all
;Filename TypeAheadTest.pb
Structure comboboxinfo
cbSize.l
rcItem.RECT
rcButton.RECT
stateButton.l
hwndCombo.l
hwndEdit.l
hwndList.l
EndStructure
Global cbinfo.comboboxinfo
Global oldcomboProc
Define tb
cbinfo\cbsize=SizeOf(comboboxinfo)
Procedure.i ComboboxAutoComplete(hWnd, uMsg, wParam, lParam)
Protected result
Protected acg
Protected spos.l
Protected epos.l
Protected matchesfound
Protected x
Protected match
Protected ks
Protected addchar$
Select uMsg
Case #WM_CHAR
acg=GetActiveGadget()
SendMessage_(hwnd, #EM_GETSEL, @spos.l, @epos.l)
matchesfound=0
For x=0 To CountGadgetItems(acg)-1
If LCase(Left(GetGadgetText(acg),spos)+LCase(Chr(wParam)))=LCase(Left(GetGadgetItemText(acg,x),spos+1)) And epos=Len(GetGadgetText(acg))
matchesfound+1
match=x
If matchesfound
Break
EndIf
EndIf
Next x
If matchesfound=1
ks=GetKeyState_(#VK_SHIFT)
If ks<2
addchar$=LCase(Chr(wparam))
Else
addchar$=UCase(Chr(wparam))
EndIf
If match
SetGadgetState(acg,match)
EndIf
SetGadgetText(acg,GetGadgetItemText(acg,match))
SendMessage_(hwnd,#EM_SETSEL,spos+1,epos+999)
SendMessage_(hwnd,#EM_SCROLLCARET,0,0)
result=0
Else
result = CallWindowProc_(oldcomboproc, hWnd, uMsg, wParam, lParam)
EndIf
Default
result = CallWindowProc_(oldcomboproc, hWnd, uMsg, wParam, lParam)
EndSelect
ProcedureReturn result
EndProcedure
Procedure SetComboBoxAuto(ID)
GetComboBoxInfo_(GadgetID(ID),@cbinfo)
tb=cbinfo.comboboxinfo\hwndedit
oldcomboproc=SetWindowLongPtr_(tb,#GWLP_WNDPROC,@ComboboxAutoComplete())
EndProcedure
;Test window is here
If OpenWindow(1,0,0,320,300,"Type ahead test",#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
ComboBoxGadget(10, 20, 20 ,200 ,25 ,#PB_ComboBox_Editable)
SetComboBoxAuto(10)
AddGadgetItem(10,-1,"abc")
AddGadgetItem(10,-1,"abcdef")
AddGadgetItem(10,-1,"bbbbbbbbb")
AddGadgetItem(10,-1,"cdef")
SetGadgetState(10,0)
SetActiveGadget(10)
Repeat
e=WaitWindowEvent()
Until e=#PB_Event_CloseWindow
CloseWindow(1)
EndIf