Hi, apologies for my late return to this topic from a while back. A couple of things:
1) Note that what I am sub-classing is not the entire ComboBox, but rather the Edit Control sub-component of that ComboBox. So as long as you are only ever subclassing other comboboxes in your program in this exact same way using this autocomplete routine, you are fine to use "oldcomboproc" consistently for all of them at all times, as Netmaestro pointed out. If however you subclass another combobox in a totally different way, be sure not to use "oldcomboproc" since it is not in fact the default window procedure for combobox gadgets/controls in general, but rather the default winproc for Edit controls.
2) I have thrown this new example together rather quickly so it may possibly contain bugs I didn't notice, but it seems to work as you want for displaying images along with their selections in Image-enabled ComboBoxes:
Code: Select all
Global oldcomboProc
UsePNGImageDecoder()
LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png")
Procedure.i ComboAutoComplete(hWnd, uMsg, wParam, lParam)
Protected result
Select uMsg
Case #WM_CHAR
acg=GetActiveGadget() ;GetDlgCtrlID_(hwnd)
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>1: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
SetGadgetState(acg,match)
SendMessage_(hwnd, #EM_SETSEL, spos+1, epos+999)
result=0
Else
g$=GetGadgetText(acg)
SetGadgetState(acg,-1)
SetGadgetText(acg,g$)
SendMessage_(hwnd, #EM_SETSEL, spos, epos+999)
result = CallWindowProc_(oldcomboproc, hWnd, uMsg, wParam, lParam)
EndIf
Default
result = CallWindowProc_(oldcomboproc, hWnd, uMsg, wParam, lParam)
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0, 0, 0, 270, 140, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
hWnd = ComboBoxGadget(0, 10, 10, 250, 21, #PB_ComboBox_Editable|#PB_ComboBox_Image)
hWnd = GetWindow_(hWnd, #GW_CHILD)
hWndEdit = FindWindowEx_(hWnd, 0, "EDIT", 0)
oldcomboproc = SetWindowLong_(hWndEdit, #GWL_WNDPROC, @ComboAutoComplete())
AddGadgetItem(0, -1, "Washington")
AddGadgetItem(0, -1, "Jefferson")
AddGadgetItem(0, -1, "Lincoln",ImageID(0))
AddGadgetItem(0, -1, "Franklin")
AddGadgetItem(0, -1, "Walters")
SetActiveGadget(0)
Repeat
W=WaitWindowEvent()
Until W = #PB_Event_CloseWindow