Page 1 of 1

Gadget in statusBar

Posted: Mon Feb 02, 2009 11:20 am
by Micko
Hi Guys !
what about your morning, for me not so cool because i have one problem
i just want to put some gadget in Statusbar but seems difficult know. please i need a help

Code: Select all

Enumeration
  #Window_0
EndEnumeration
Enumeration
  #StatusBar_Window_0
EndEnumeration
Enumeration
  #CheckBox_0
EndEnumeration
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 653, 201, 181, 105, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
     CheckBoxGadget(#CheckBox_0, 35, 75, 130, 25, "put me in the statusBar")
    If CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0))
       SetParent_(#CheckBox_0,GadgetID(#StatusBar_Window_0))
       UpdateWindow_(GadgetID(#StatusBar_Window_0))
    EndIf
  EndIf
EndProcedure

OpenWindow_Window_0()

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #CheckBox_0
      EndIf
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        Break
      EndIf
  EndSelect
ForEver

thanks

Re: Gadget in statusBar

Posted: Mon Feb 02, 2009 11:24 am
by eesau

Code: Select all

SetParent_(#CheckBox_0,GadgetID(#StatusBar_Window_0))
I can't test it right now, but does using StatusBarID() instead of GadgetID work?

Posted: Mon Feb 02, 2009 11:27 am
by srod
A few problems. First your positioning of the CheckBox gadget puts it out of the visible field once you place it in the statusbar and yes, as eesau pointed out, there are problems with your use of SetParent_().

Try the following :

Code: Select all

Procedure OpenWindow_Window_0() 
  If OpenWindow(#Window_0, 653, 201, 181, 105, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar) 
     CheckBoxGadget(#CheckBox_0, 0, 0, 130, 25, "put me in the statusBar") 
    If CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0)) 
       SetParent_(GadgetID(#CheckBox_0),StatusBarID(#StatusBar_Window_0)) 
       UpdateWindow_(GadgetID(#StatusBar_Window_0)) 
    EndIf 
  EndIf 
EndProcedure 

Posted: Mon Feb 02, 2009 11:35 am
by gnozal
This should also work (without API) :

Code: Select all

Enumeration 
  #Window_0 
EndEnumeration 
Enumeration 
  #StatusBar_Window_0 
EndEnumeration 
Enumeration 
  #CheckBox_0 
  #CheckBox_1 
EndEnumeration 
Define.l Event, EventWindow, EventGadget, EventType, EventMenu 
Procedure OpenWindow_Window_0() 
  If OpenWindow(#Window_0, 653, 201, 181, 105, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar) 
    If CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0)) 
      OldGadgetList = UseGadgetList(StatusBarID(#StatusBar_Window_0))
      CheckBoxGadget(#CheckBox_0, 1, 4, 130, 15, "put me in the statusBar") 
      UseGadgetList(OldGadgetList)
    EndIf 
    CheckBoxGadget(#CheckBox_1, 0, 0, 160, 20, "don't put me in the statusBar") 
  EndIf 
EndProcedure

OpenWindow_Window_0() 

Repeat 
  Event = WaitWindowEvent() 
  Select Event 
    Case #PB_Event_Gadget 
      EventGadget = EventGadget() 
      EventType = EventType() 
      If EventGadget = #CheckBox_0 
      EndIf 
    Case #PB_Event_CloseWindow 
      EventWindow = EventWindow() 
      If EventWindow = #Window_0 
        CloseWindow(#Window_0) 
        Break 
      EndIf 
  EndSelect 
ForEver

Posted: Mon Feb 02, 2009 1:33 pm
by Micko
thanks Boss for your very fast answers !

Srod and Gnozal code work well
:)
@ eesau
you are right