CreateToolBar()

Syntax

Result = CreateToolBar(#ToolBar, WindowID)
Description
Creates a new empty toolbar on the given window.

Parameters

#ToolBar A number to identify the new toolbar. #PB_Any can be used to auto-generate this number.
WindowID The window for the new toolbar. It can be obtained using the WindowID() function.

Return value

Returns nonzero if the toolbar was created successfully and zero if not. If #PB_Any was used for the #ToolBar parameter then the generated number is returned on success.

Remarks

This toolbar become the default toolbar for creation and it's possible to use ToolBarImageButton() and ToolBarSeparator() to add some items to this toolbar.

The events are handled the same way than menu events, using the function EventMenu(). ToolBars are often used as shortcut for menu items, so when assigning the same menu item number to a toolbar button, both events are handled using the same code.

Example

  Procedure MenuEvents()
    Debug "ToolBar item selected: " + EventMenu()
  EndProcedure
  
  If OpenWindow(0, 0, 0, 295, 260, "ToolBar example", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    
    CreateImage(0, 16, 16, 32, #PB_Image_Transparent)
    If StartDrawing(ImageOutput(0))
      Circle(8, 8, 7, RGB(255, 0, 0))
      StopDrawing()
    EndIf
    
    If CreateToolBar(0, WindowID(0))
      ToolBarImageButton(0, ImageID(0))
      ToolBarImageButton(2, ImageID(0))
      ToolBarSeparator()
      ToolBarImageButton(3, ImageID(0))
      ToolBarToolTip(0, 3, "Cut")
      
      ToolBarImageButton(4, ImageID(0))
      ToolBarToolTip(0, 4, "Copy")
    EndIf
    
    DisableToolBarButton(0, 2, 1) ; Disable the button '2'
      
    BindEvent(#PB_Event_Menu, @MenuEvents())
  EndIf

See Also

ToolBarImageButton(), ToolBarSeparator(), FreeToolBar()
ToolBar Index - DisableToolBarButton() ->