Toolbar ComboBox

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Toolbar ComboBox

Post by eddy »

Code updated for 5.20+

Add a comboxbox gadget in toolbar without any problem of placement. :D

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
Last edited by eddy on Thu Jun 24, 2004 8:10 pm, edited 4 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Fred
Administrator
Administrator
Posts: 18254
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Nice trick !
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Post by Nico »

Code: Select all

Procedure ToolBarComboBox(ComboBoxID,offsetX,offsetY,w,h)        
   CurrentToolbar=FindWindowEx_(WindowID(), 0, "ToolbarWindow32", 0) 
8O

Code: Select all

Procedure ToolBarComboBox(ComboBoxID,CurrentToolbar,offsetX,offsetY,w,h)  
........
 ToolBarComboBox(#GADGET_Combo,hToolbar,0,1,70,200)  
:)
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: Toolbar ComboBox

Post by NoahPhense »

Sweet.. nice work!

- np

Andre.. CodeArchiv ;)
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

@Nico
Code updated - now there's two versions
This procedure works with toolbar in container. :D

Code: Select all

ContainerGadget(#GADGET_container,....)
hToolbar=CreateToolBar(#TOOLBAR, GadgetID(#GADGET_Container)) 
ToolBarComboBoxEx (#GADGET_Combo,0,0,30,100,hToolbar) 
PS : It's such a pity there's no toolbarID() command

Code: Select all

CurrentToolbar=ToolbarID()
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply