For example:
1. When I type 'An', then 'Andrew' is displayed.
2. The following cursor down action leads to 'Anna'.
3. Finally, typing of the letter 'c' results in 'Carol'.
Great - everything is okay!
But using PB 5.50 or PB 5.60 instead produces a strange behaviour:
Steps 1. and 2. will show the same results as above. So far, so good. But step 3 - i. e. typing of 'c' - doesn't result in 'Carol'.
So, why this difference between 5.40 and 5.50/5.60? Is it because of unicode compilation?
Code: Select all
Declare ComboboxAutoComplete(WindowID, Message, wParam, lParam)
#window = 0
#combo = 0
Global index_auto ;will be changed in ComboxAutoComplete procedure
OpenWindow(#Window, 0, 0, 400, 200, "Combobox with AutoComplete", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
ComboBoxGadget(#combo, 40, 40, 260, #Null, #PB_ComboBox_Editable | #CBS_NOINTEGRALHEIGHT)
MoveWindow_(GadgetID(#combo),GadgetX(#combo),GadgetY(#combo),GadgetWidth(#combo), 22, #True)
AddGadgetItem(#combo, -1, "Albert")
AddGadgetItem(#combo, -1, "Alexander")
AddGadgetItem(#combo, -1, "Andrew")
AddGadgetItem(#combo, -1, "Anna")
AddGadgetItem(#combo, -1, "Bernie")
AddGadgetItem(#combo, -1, "Bridget")
AddGadgetItem(#combo, -1, "Carol")
AddGadgetItem(#combo, -1, "Clair")
SetActiveGadget(#combo)
SetWindowCallback(@ComboboxAutoComplete())
Repeat
event = WaitWindowEvent()
If event = #PB_Event_CloseWindow
quit = #True
EndIf
If event = #PB_Event_Gadget
If EventGadget() = #combo
If GetAsyncKeyState_(#VK_DOWN)
ind = index_auto + 1
SetGadgetState(#combo, ind)
index_auto = ind
EndIf
If GetAsyncKeyState_(#VK_UP)
ind = index_auto - 1
If ind < 0
ind = 0
EndIf
SetGadgetState(#combo, ind)
index_auto = ind
EndIf
EndIf
EndIf
Until quit = #True
Procedure ComboboxAutoComplete(WindowID, Message, wParam, lParam)
Protected result.l
Protected comboWert.s, comboLang.l, comboStart.l, parameter.l, start.l, ende.l
Static comboIndex.l
result = #PB_ProcessPureBasicEvents
Select Message
;Case #WM_PAINT
Case #WM_COMMAND
Select lParam
Case GadgetID(#combo)
Select (wParam >> 16 & $FFFF)
Case #CBN_EDITUPDATE
If GetAsyncKeyState_(#VK_BACK) Or GetAsyncKeyState_(#VK_DELETE)
comboWert = GetGadgetText(#combo)
If comboIndex >= 0
combowert = Left(comboWert, Len(combowert)-1)
EndIf
Else
comboWert = GetGadgetText(#combo)
EndIf
;
comboIndex = SendMessage_(lParam, #CB_FINDSTRING, -1, @comboWert)
comboStart = Len(comboWert) ;length of typed text
If combostart = 0
SetGadgetText(#combo, "")
EndIf
;
If comboIndex >= 0 ;there is a match
SendMessage_(lParam, #CB_SETCURSEL, comboIndex, 0)
comboLang = Len(GetGadgetText(#combo))
parameter = (comboLang << 16 & $FFFFFFFF) + comboStart
SendMessage_(lParam, #CB_SETEDITSEL, 0, parameter)
index_auto = GetGadgetState(#combo)
EndIf
EndSelect
EndSelect
EndSelect
ProcedureReturn result
EndProcedure