Page 1 of 1
toolbar question
Posted: Sat Jan 16, 2010 12:38 am
by fabio
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
Re: toolbar question
Posted: Sat Jan 16, 2010 12:51 am
by netmaestro
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
Re: toolbar question
Posted: Sat Jan 16, 2010 12:59 am
by srod
Ah, too slow again!
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)
Re: toolbar question
Posted: Sat Jan 16, 2010 1:12 am
by netmaestro
Thanks srod, I didn't know that one and I've been meaning to look into it- now I don't have to!
Re: toolbar question
Posted: Sat Jan 16, 2010 5:17 am
by fabio
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
Re: toolbar question
Posted: Sat Jan 16, 2010 11:12 am
by Kaeru Gaman
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.
Re: toolbar question
Posted: Sat Jan 16, 2010 4:37 pm
by fabio
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
Re: toolbar question
Posted: Sat Jan 16, 2010 5:25 pm
by Kaeru Gaman
nope.
the API comes with your OS.
PureBasic has a whole lot of those OS-Specific functions imported, some even wrapped.
Re: toolbar question
Posted: Sat Jan 16, 2010 7:46 pm
by fabio
Thanks again, Kaeru. Time to code
Fabio