Page 2 of 2
Re: Autocomplete for Comboboxgadget - Simple version
Posted: Sun Jun 05, 2011 9:18 pm
by Fangbeast
netmaestro wrote:oldcomboproc is only for a single combo box as I understand it??
'oldcomboproc' is going to be the same for all comboboxes you subclass as it's the default combobox procedure. You can safely use this with multiple combo boxes.
Thank you NetMaestro, simply very useful to me. Don't have much brain left over while I am studying (at my age damn it!!) and taking exams.
Soon to have blessed relief from them.
Re: Autocomplete for Comboboxgadget - Simple version
Posted: Tue Jun 07, 2011 4:02 am
by Fangbeast
How do I make this work if the combobox has images?
When I start my program, the first entry is missing the image. When I start typing in the combo, the autocomplete works but no corresponding image is set for the completed item when it fully matches something in the combo list.
I imagine that a whole new approach is required??
Re: Autocomplete for Comboboxgadget - Simple version
Posted: Fri Jul 08, 2011 10:13 pm
by mesozorn
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
Re: Autocomplete for Comboboxgadget - Simple version
Posted: Sat Oct 15, 2011 1:36 pm
by Seldon
The first published code it works under 4.51 , I think because PB now uses again Windows Combobox class if #PB_ComboBox_Image is NOT used. Actually if you set #PB_ComboBox_Image flag, it doesn't work (I guess in such case it uses ComboBoxEx class).
Re: Autocomplete for Comboboxgadget - Simple version
Posted: Sat Oct 15, 2011 2:52 pm
by Ramihyn_
Seldon wrote:The first published code it works under 4.51 , I think because PB now uses again Windows Combobox class if #PB_ComboBox_Image is NOT used. Actually if you set #PB_ComboBox_Image flag, it doesn't work (I guess in such case it uses ComboBoxEx class).
Check
http://www.purebasic.fr/blog/?p=336
Re: Autocomplete for Comboboxgadget - Simple version
Posted: Sun Oct 16, 2011 1:11 pm
by Seldon
Yes, thanks. It says "Combobox" & "WC_COMBOBOXEX" classes, so I suppose it works that way. Actually there was a thread in the forum and the great PB team provided such a 'smart' solution to let older code that used API functions to work.

Re: Autocomplete for Comboboxgadget - Simple version
Posted: Sun Oct 16, 2011 1:38 pm
by netmaestro
For those who don't read (or perhaps believe) blogs, there is always this option:
Code: Select all
OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ComboBoxGadget(0,20,40,200,20)
ComboBoxGadget(1,20,70,200,20, #PB_ComboBox_Image)
cn1$ = Space(50)
cn2$ = Space(50)
GetClassName_(GadgetID(0), @cn1$, 50)
GetClassName_(GadgetID(1), @cn2$, 50)
AddGadgetItem(0,-1,cn1$)
AddGadgetItem(1,-1,cn2$)
SetGadgetState(0,0)
SetGadgetState(1,0)
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Autocomplete for Comboboxgadget - Simple version
Posted: Thu Jan 05, 2017 12:39 pm
by HanPBF
Thanks a lot for this auto complete example!
Why does it only work with
ComboBoxGadget(#PB_Any, X, Y, W, H, #PB_ComboBox_Image | #PB_ComboBox_Editable)
If I leave #PB_ComboBox_Image off the statement, FindwindowEx_ does result in 0...
Thanks!