Toolbar ComboBox
Posted: Thu Jun 24, 2004 2:29 pm
Code updated for 5.20+
Add a comboxbox gadget in toolbar without any problem of placement.
code updated with two versions :
- ToolBarComboBox (ComboBoxID,offsetX,offsetY,w,h)
- ToolBarComboBoxEx (ComboBoxID,offsetX,offsetY,w,h,hToolbar)
Add a comboxbox gadget in toolbar without any problem of placement.

code updated with two versions :
- ToolBarComboBox (ComboBoxID,offsetX,offsetY,w,h)
- ToolBarComboBoxEx (ComboBoxID,offsetX,offsetY,w,h,hToolbar)
Code: Select all
Enumeration
#WIN
#TOOLBAR
#GADGET_Combo
EndEnumeration
; /////////////////////////////
; Add combobox in TOOLBAR
; Advance version : you can use any handle of Toolbar
; /////////////////////////////
Procedure ToolBarComboBoxEx(ComboBoxID,offsetX,offsetY,w,h,hToolbar)
;add separator (width)
pos=SendMessage_(hToolbar,#TB_BUTTONCOUNT,0,0)
ToolBarSeparator()
SendMessage_(hToolbar,#TB_GETBUTTON,pos,@separator.TBBUTTON)
separator\iBitmap=offsetX+w
SendMessage_(hToolbar,#TB_DELETEBUTTON,pos,0)
SendMessage_(hToolbar,#TB_INSERTBUTTON,pos,separator)
;combobox position
SendMessage_(hToolbar,#TB_GETITEMRECT,pos,@rc.RECT)
x=offsetX+rc\left
y=offsetY
;add combobox
UseGadgetList(hToolbar)
ComboBoxGadget(ComboBoxID,x,y,w,h)
UseGadgetList(WindowID(#Win))
EndProcedure
; /////////////////////////////
; Add combobox in TOOLBAR
; /////////////////////////////
Procedure ToolBarComboBox(ComboBoxID,offsetX,offsetY,w,h)
CurrentToolbar=FindWindowEx_(WindowID(#Win), 0, "ToolbarWindow32", 0)
ToolBarComboBoxEx(ComboBoxID,offsetX,offsetY,w,h,CurrentToolbar)
EndProcedure
; /////////////////////////////
; code example
; /////////////////////////////
OpenWindow(#WIN,200,100,300,240,"Test",#PB_Window_SystemMenu)
hToolbar=CreateToolBar(#TOOLBAR, WindowID(0))
ToolBarStandardButton(1, #PB_ToolBarIcon_New)
ToolBarStandardButton(2, #PB_ToolBarIcon_New)
ToolBarSeparator()
ToolBarStandardButton(3, #PB_ToolBarIcon_New)
;new combobox
ToolBarComboBox(#GADGET_Combo,0,1,70,20)
AddGadgetItem(#GADGET_Combo,-1,"A")
AddGadgetItem(#GADGET_Combo,-1,"B")
AddGadgetItem(#GADGET_Combo,-1,"C")
SetGadgetState(#GADGET_Combo,2)
GadgetToolTip(#GADGET_Combo,"Combobox in toolbar")
ToolBarStandardButton(4, #PB_ToolBarIcon_New)
ToolBarSeparator()
ToolBarStandardButton(5, #PB_ToolBarIcon_New)
ToolBarStandardButton(6, #PB_ToolBarIcon_New)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow