Hello, I am making my first steps and would like to know how to use more than one toolbar in a window.
I have been based in toolbar.pb, but after adding a second toolbar, the first disappear.
Thank you in advance.
Fabio
toolbar question
- netmaestro
- PureBasic Bullfrog

- Posts: 8453
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: toolbar question
You can create several toolbars and place them on a window in various positions using Container gadgets. In the example we modify the PB doc demo to use two toolbars:
Code: Select all
If OpenWindow(0, 100, 200, 195, 260, "ToolBar example", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
If CreateToolBar(0, WindowID(0))
ToolBarStandardButton(0, #PB_ToolBarIcon_New)
ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
ToolBarSeparator()
ToolBarStandardButton(3, #PB_ToolBarIcon_Print)
ToolBarToolTip(0, 3, "Print")
ToolBarStandardButton(4, #PB_ToolBarIcon_Find)
ToolBarToolTip(0, 4, "Find a document")
ToolBarSeparator()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
; The .ico format is available only on Windows
ToolBarImageButton(5, LoadImage(0, #PB_Compiler_Home+"examples\sources\Data\CdPlayer.ico"))
CompilerEndIf
EndIf
If CreateMenu(0, WindowID(0))
MenuTitle("Project")
MenuItem(0, "New")
MenuItem(1, "Open")
MenuItem(2, "Save")
EndIf
;
; Attach our previously created ToolBar to this window
;
DisableToolBarButton(0, 2, 1) ; Disable the button '2'
; Repeat the whole toolbar in a container
ContainerGadget(0, 0,100,195,32)
If CreateToolBar(1, GadgetID(0)) ; <----------------- Note the toolbar is created in the container
ToolBarStandardButton(0, #PB_ToolBarIcon_New)
ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
ToolBarSeparator()
ToolBarStandardButton(3, #PB_ToolBarIcon_Print)
ToolBarToolTip(0, 3, "Print")
ToolBarStandardButton(4, #PB_ToolBarIcon_Find)
ToolBarToolTip(0, 4, "Find a document")
ToolBarSeparator()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
; The .ico format is available only on Windows
ToolBarImageButton(5, LoadImage(0, #PB_Compiler_Home+"examples\sources\Data\CdPlayer.ico"))
CompilerEndIf
EndIf
;
; The event loop. A ToolBar event is like a Menu event (as tools are shortcut for menu the most
; of the time). This is handy, as if the ToolBar buttons and the MenuItem have the same ID, then
; the same operation can be done on both action without any adds..
;
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Menu
MessageRequester("Information", "ToolBar or Menu ID: "+Str(EventMenu()), 0)
Case #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndSelect
Until Quit = 1
EndIf
End ; All the opened windows are closed automatically by PureBasic
BERESHEIT
Re: toolbar question
Ah, too slow again!
Oh well. I can add one tip though; you can remove the horizontal divider line with the following :
Oh well. I can add one tip though; you can remove the horizontal divider line with the following :
Code: Select all
SetWindowLong_(ToolBarID(1), #GWL_STYLE, GetWindowLong_(ToolBarID(1), #GWL_STYLE)|#CCS_NODIVIDER)I may look like a mule, but I'm not a complete ass.
- netmaestro
- PureBasic Bullfrog

- Posts: 8453
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: toolbar question
Thanks srod, I didn't know that one and I've been meaning to look into it- now I don't have to!
BERESHEIT
Re: toolbar question
Container was the magic word
. The example works great, thank you very much for your help.
I have a few more questions, please.
If I am right, SetWindowLong_ only works in win, what happens if I try to run this function in other OS? Maybe a crash?
And a more general question, when I compile this example in Windows, the resulting exe will run only in win, or the same executable will work in other OS (Linux, Mac) as well?
Fabio
I have a few more questions, please.
If I am right, SetWindowLong_ only works in win, what happens if I try to run this function in other OS? Maybe a crash?
And a more general question, when I compile this example in Windows, the resulting exe will run only in win, or the same executable will work in other OS (Linux, Mac) as well?
Fabio
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: toolbar question
2. you need to compile on each OS for it's own, with it's own compiler. executables are not cross-platform, only native code is.
1. implied: the function is unknown, the code will not compile.
1. implied: the function is unknown, the code will not compile.
oh... and have a nice day.
Re: toolbar question
OK, thank you very much for the info, Kaeru.
I need to make one last question, the version of Purebasic on either Linux and Mac comes with its own api too? Just like the win version comes with the winapi?
Fabio
I need to make one last question, the version of Purebasic on either Linux and Mac comes with its own api too? Just like the win version comes with the winapi?
Fabio
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: toolbar question
nope.
the API comes with your OS.
PureBasic has a whole lot of those OS-Specific functions imported, some even wrapped.
the API comes with your OS.
PureBasic has a whole lot of those OS-Specific functions imported, some even wrapped.
oh... and have a nice day.
Re: toolbar question
Thanks again, Kaeru. Time to code 
Fabio
Fabio
