Page 1 of 1

ToolBar hide & show

Posted: Tue Jun 24, 2003 1:51 pm
by wcardoso
friends, how can I hide and show a toolbar in a window ?. I need add this feature to gain client size space when the user need it by checking a menu option... :roll:

Posted: Tue Jun 24, 2003 2:30 pm
by Fred
Try:

Code: Select all

*YourToolBar = CreateToolbar(....)
ShowWindow_(*YourToolBar, #SW_HIDE) ; will hide it
ShowWindow_(*YourToolBar, #SW_SHOWNORMAL) ; will show it

Posted: Tue Jun 24, 2003 8:15 pm
by GPI
btw:

A ToolBarHeight() (like MenuHeigth()) would be nice.

GPI

Posted: Wed Jun 25, 2003 12:34 pm
by wcardoso
Fred, sorry but your example don´t work here. I´d searched in the API but there isn´t any function that do it.
I have tested the Danilo´s TBPro and work great, but the question is how Danilo do to hide the toolbar ?
:roll:

Posted: Wed Jun 25, 2003 2:35 pm
by PB
> Fred, sorry but your example don´t work here

Works just fine for me... can we see your code to see what's wrong?

Posted: Wed Jun 25, 2003 5:02 pm
by freedimension
Fred wrote:

Code: Select all

*YourToolBar = CreateToolbar(....)
ShowWindow_(*YourToolBar, #SW_HIDE) ; will hide it
ShowWindow_(*YourToolBar, #SW_SHOWNORMAL) ; will show it
Is the * really necessary?

Code: Select all

YourToolBar = CreateToolbar(....)
ShowWindow_(YourToolBar, #SW_HIDE)
ShowWindow_(YourToolBar, #SW_SHOWNORMAL)
would suffice, or not?

Posted: Wed Jun 25, 2003 7:45 pm
by Fred
It would work too. I like use pointer when dealing which them, but everyone can do like he wants :)

Posted: Wed Jun 25, 2003 8:08 pm
by wcardoso
PB, here is the code...

Code: Select all

Global  TBHandle.l, Quit.l
.....
Quit = 0
.....
Declare VisiTB()
.....
If OpenWindow(0, 50, 50, 150, 100, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "ToolBar test")
  If CreateMenu(0, WindowID())
    MenuTitle("Test")
      MenuItem(0, "Toggle")
    SetMenuItemState(0, 0, 1)
  EndIf
  *TBHandle = CreateToolBar(10, WindowID())
    CatchImage(0,?Btn0)
    CatchImage(1,?Btn1)
    CatchImage(2,?Btn2)
    ToolBarImageButton(0,UseImage(0))
    ToolBarImageButton(1,UseImage(1))
    ToolBarSeparator()
    ToolBarImageButton(3,UseImage(2))
    For n = 0 To 3
    FreeImage(n)
    Next
  Goto LoopEvents:
EndIf
....
LoopEvents:
Repeat
  Select WaitWindowEvent()
    Case #PB_EventMenu
      Select EventMenuID()
        Case 0
          VisiTB()
      EndSelect
    Case #WM_CLOSE
      Quit = 1
  EndSelect
Until Quit = 1
......
End
......
Procedure VisiTB()
  If GetMenuItemState(0, 0) = 0
    SetMenuItemState(0, 0, 1)
    ShowWindow_(*TBHandle, #SW_SHOWNORMAL)
  Else
    SetMenuItemState(0, 0, 0)
    ShowWindow_(*TBHandle, #SW_HIDE)
  EndIf   
EndProcedure
......
Of course this is part of the real program, but I extract the relevants parts...
Please help me.

P.D. I´m programming in a ThinkPad Celeron notebook with 128 Mb of RAM

Posted: Wed Jun 25, 2003 8:17 pm
by wcardoso
Ok, ok... now it´s working !!. I´d need to get out the asterisk (*) and all works fine now. Thanks everybody :lol:

Posted: Wed Jun 25, 2003 8:34 pm
by Andre
Here is a small code I put together yesterday from the given hints.... :wink:

Code: Select all

OpenWindow(0,100,150,300,120,#PB_Window_SystemMenu,"ToolBar - Show and Hide") 
hToolbar = CreateToolBar(1, WindowID(0)) 
ToolBarStandardButton(1, #PB_ToolBarIcon_New) 
ToolBarStandardButton(2, #PB_ToolBarIcon_Open) 
ToolBarStandardButton(3, #PB_ToolBarIcon_Save) 

If CreateGadgetList(WindowID())
  ButtonGadget(0,50,50,200,20,"Hide ToolBar") : Shown = 1
EndIf

Repeat
  ev.l = WaitWindowEvent()
  gad.l = EventGadgetID()
  If ev = #PB_EventGadget
    If gad = 0
      If Shown = 1
        ShowWindow_(hToolbar, #SW_HIDE) ; now hide toolbar 
        SetGadgetText(0,"Show ToolBar")
        Shown = 0
      Else
        ShowWindow_(hToolbar, #SW_SHOWNORMAL) ; now shot toolbar
        SetGadgetText(0,"Hide ToolBar")
        Shown = 1
      EndIf
    EndIf
  EndIf
Until ev.l = #PB_Event_CloseWindow