Gadget in statusBar

Just starting out? Need help? Post your questions and find answers here.
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Gadget in statusBar

Post 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
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: Gadget in statusBar

Post 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?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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 
I may look like a mule, but I'm not a complete ass.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

thanks Boss for your very fast answers !

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