Cannot get simple combobox type ahead to work in 64-bit

Just starting out? Need help? Post your questions and find answers here.
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 274
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Cannot get simple combobox type ahead to work in 64-bit

Post by DeanH »

I am using some code I found here on the forum to allow type-ahead for a combobox. My apologies to the person who originally wrote the code. I have not been able to find the correct reference so you can be named. This code works in PB 32-bit but not in 64-bit. (I'm using PB 5.72 and Windows 10.) Any ideas on how this can be done? The type-ahead selects an entry from the dropdown list.

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
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: Cannot get simple combobox type ahead to work in 64-bit

Post by Mijikai »

I guess the structure is wrong.
Change all .l to .i and try if that helps.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Cannot get simple combobox type ahead to work in 64-bit

Post by infratec »

Not all l to i :!:
A DWORD is always a long.

Code: Select all

typedef struct tagCOMBOBOXINFO {
  DWORD cbSize;
  RECT  rcItem;
  RECT  rcButton;
  DWORD stateButton;
  HWND  hwndCombo;
  HWND  hwndItem;
  HWND  hwndList;
}
Should be

Code: Select all

Structure comboboxinfo
   cbSize.l
   rcItem.RECT
   rcButton.RECT
   stateButton.l
   hwndCombo.i
   hwndEdit.i
   hwndList.i
EndStructure
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 274
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: Cannot get simple combobox type ahead to work in 64-bit

Post by DeanH »

That's it! Thank you very very much. A quick fix will make dozens of users happier.
User avatar
digital32
User
User
Posts: 30
Joined: Fri Dec 28, 2012 1:28 am

Re: Cannot get simple combobox type ahead to work in 64-bit

Post by digital32 »

I need to do a similar type ahead but I'm dealing with 30k user names. I was thinking the user would need to type at least 3 letters then I could search my list structure and populate the to X in the drop down. Anyone already written code like that?
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Cannot get simple combobox type ahead to work in 64-bit

Post by idle »

Autocompete example in scintilla gadget
viewtopic.php?p=547425#p547425
User avatar
digital32
User
User
Posts: 30
Joined: Fri Dec 28, 2012 1:28 am

Re: Cannot get simple combobox type ahead to work in 64-bit

Post by digital32 »

@idle Very Impressive with memory compression. Love it. This will work nicely.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Cannot get simple combobox type ahead to work in 64-bit

Post by idle »

digital32 wrote: Fri Sep 09, 2022 10:39 pm @idle Very Impressive with memory compression. Love it. This will work nicely.
There's also Squint3 but it's not serializable if your using dynamic data squint3 will use 4 times less memory
viewtopic.php?p=586544#p586544
User avatar
jacdelad
Addict
Addict
Posts: 1992
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Cannot get simple combobox type ahead to work in 64-bit

Post by jacdelad »

I stumbled over this piece of code, which works well, but one sidenote: Calling GetComboBoxInfo_() with a combobox with icons (#PB_ComboBox_Image) does not work for whatever reason. Maybe someone can help.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply