This is a modification of a code which I wrote 12 years ago on VB6, which splits the ComboBox into its component elements, and subclasses only the embedded editor control. Seems that PureBasic's ComboBoxGadget is built the same way:
Code: Select all
;==========================================================================
;
; Subclassing the ComboBox Gadget to intercept the [ENTER] key by TI-994A
;
; The ComboBox class is a combination of an editor control and a listview
; control. The handle to the editor component, which is the first child
; window in the class, is obtained by using the FindWindowEx API function.
; With that, the editor control can be subclassed to trap keyboard events.
;
;==========================================================================
Enumeration
#MainWindow
#ComboBox
#ComboBox2
#TextGadget
#TextGadget2
EndEnumeration
Procedure ComboEditorProc(hWnd, uMsg, wParam, lParam)
Shared sysProc
Define.l result
If uMsg = #WM_CHAR And wparam = #VK_RETURN
If Not SendMessage_(GadgetID(#ComboBox),#CB_GETDROPPEDSTATE, 0, 0)
SendMessage_(GadgetID(#ComboBox),#CB_SHOWDROPDOWN, 1, 0)
result = 0
Else
result = CallWindowProc_(sysProc, hWnd, uMsg, wParam, lParam)
EndIf
Else
result = CallWindowProc_(sysProc, hWnd, uMsg, wParam, lParam)
EndIf
ProcedureReturn result
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 500, 200, "Subclassed ComboBox", wFlags)
ComboBoxGadget(#ComboBox, 25, 40, 200, 22, #PB_ComboBox_Editable)
ComboBoxGadget(#ComboBox2, 275, 40, 200, 22, #PB_ComboBox_Editable)
TextGadget(#TextGadget, 25, 20, 200, 22, "Keyboard Activated ComboBox")
TextGadget(#TextGadget2, 275, 20, 200, 22, "Standard ComboBox")
Restore scientists
For readData = 1 To 8
Read.s names$
AddGadgetItem(#ComboBox, -1, names$)
AddGadgetItem(#ComboBox2, 0, names$)
Next readData
SetActiveGadget(#ComboBox)
hWndEditor = FindWindowEx_(GadgetID(#ComboBox), 0, 0, 0)
sysProc = SetWindowLongPtr_(hWndEditor, #GWL_WNDPROC, @ComboEditorProc())
While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend
DataSection
scientists:
Data.s "Albert Einstein", "Isaac Newton", "Charles Darwin", "Guglielmo Marconi"
Data.s "Galileo Galilei", "Leonardo da Vinci", "René Descartes", "Thomas Edison"
EndDataSection