Restored from previous forum. Originally posted by El_Choni.
Hi,
UPDATE: modified for PB 3.20, added example with editable ComboBox gadget.
This solves a problem in PB which doesn't handle correctly ComboBox selection changing events:
Using editable ComboBox gadget:
Code: Select all
#MainWndFlags = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
#WindowWidth = 480
Global CB_hWnd.l, lpch.l
Procedure Error(errorstring.s)
MessageRequester("Error", errorstring, #MB_ICONERROR)
End
EndProcedure
Main_hWnd = OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, #WindowWidth, 110, "Editable ComboBox item selection event catching example:", #MainWndFlags)
If Main_hWnd
CB_hWnd = ComboBoxGadget(0, 5, 5, #WindowWidth-10, 25, #PB_ComboBox_Editable)
If CB_hWnd
cchTextMax = 256
lpch = AllocateMemory(cchTextMax)
Dim item.s(7)
item(0) = "Spaghetti"
item(1) = "Great sole"
item(2) = "Potato omelette"
item(3) = "Fondue chinoise"
item(4) = "Tapioca soup"
item(5) = "Duck liver"
item(6) = "Kebap"
For i = 0 To 6
AddGadgetItem(0, -1, item(i))
Next i
ButtonGadget(1, 5, 40, (#WindowWidth/2)-15, 32, "Add")
TextGadget(2, (#WindowWidth/2)+5, 40, (#WindowWidth/2)-15, 32, "Capturing the item-selected event")
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
EventGadgetID = EventGadget()
Select EventGadgetID
Case 0
Select EventType()
Case #PB_EventType_RightClick
MessageRequester("Selection changed to:", GetGadgetText(0), 0)
EndSelect
Case 1
SendMessage_(CB_hWnd, #WM_GETTEXT, cchTextMax, lpch)
AddGadgetItem(0, -1, PeekS(lpch))
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
Else
Error("Could not create editable ComboBox gadget.")
EndIf
Else
Error("Could not open main window.")
EndIf
End
Code: Select all
#EDITCOMBOBOX = #WS_CHILD|#WS_VISIBLE|#CBS_DROPDOWN|#CBS_AUTOHSCROLL|#WS_VSCROLL ; for the combobox pull-down
#MainWndFlags = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
#WindowWidth = 480
Global CB_hWnd.l, lpch.l
Procedure Error(errorstring.s)
MessageRequester("Error", errorstring, #MB_ICONERROR)
End
EndProcedure
Procedure SelectCallback(WindowID, uMsg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_COMMAND
wNotifyCode = wParam>>16
wID = wParam & $ffff
If wNotifyCode = #CBN_SELCHANGE And lParam = CB_hWnd And wID = 0
SendMessage_(CB_hWnd, #CB_GETLBTEXT, SendMessage_(CB_hWnd, #CB_GETCURSEL, 0, 0), lpch)
MessageRequester("Selection changed to:", PeekS(lpch), 0)
EndIf
EndSelect
ProcedureReturn result
EndProcedure
hInstance = GetModuleHandle_(#Null)
Main_hWnd = OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, #WindowWidth, 110, "Editable ComboBox item selection event catching example:", #MainWndFlags)
If Main_hWnd
CB_hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE, "COMBOBOX", "ComboBoxGadget", #EDITCOMBOBOX, 5, 5, #WindowWidth-10, 100, Main_hWnd, 0, hInstance, #Null)
If CB_hWnd
; select Windows variable-pitch (proportional space) system font and apply font to the combobox
SendMessage_(CB_hWnd, #WM_SETFONT, GetStockObject_(#ANSI_VAR_FONT), #False)
cchTextMax = 256
lpch = AllocateMemory(cchTextMax)
Dim item.s(7)
item(0) = "Spaghetti"
item(1) = "Great sole"
item(2) = "Potato omelette"
item(3) = "Fondue chinoise"
item(4) = "Tapioca soup"
item(5) = "Duck liver"
item(6) = "Kebap"
For i = 0 To 6
SendMessage_(CB_hWnd, #CB_INSERTSTRING, -1, @item(i))
Next i
ButtonGadget(1, 5, 40, (#WindowWidth/2)-15, 32, "Add")
TextGadget(2, (#WindowWidth/2)+5, 40, (#WindowWidth/2)-15, 32, "Capturing the item-selected event")
SetWindowCallback(@SelectCallback())
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
EventGadgetID = EventGadget()
Select EventGadgetID
Case 1
SendMessage_(CB_hWnd, #WM_GETTEXT, cchTextMax, lpch)
SendMessage_(CB_hWnd, #CB_INSERTSTRING, -1, lpch)
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
Else
Error("Could not create editable combobox control.")
EndIf
Else
Error("Could not open main window.")
EndIf
End
El_Choni
Edited by - El_Choni on 04 July 2002 12:47:03