StatusBar - Resize
Posted: Sun Sep 07, 2008 5:01 pm
It could be cool if we can resize a field of a statusbar.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
; Demo of Changing Status Bar Field Widths AKJ 07-Sep-08
EnableExplicit
RandomSeed(ElapsedMilliseconds())
Enumeration
#winMain
#staBar
#butAllChange
EndEnumeration
; Create GUI
Define winw, winh, flags, hwin, hsta, field, stah, butw, buth
winw = 500: winh = 200
butw = 160: buth = 30
flags = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered
hwin = OpenWindow(#winMain, 0, 0, winw, winh, " Adjust Status Bar Field Widths", flags)
CreateGadgetList(hwin)
hsta = CreateStatusBar(#staBar, hwin) ; Returns status bar handle (not documented!)
For field = 0 To 2 ; Three status bar fields
AddStatusBarField(winw/3)
StatusBarText(#staBar, field, "Field "+Str(field))
Next field
stah = StatusBarHeight(#staBar)
ButtonGadget(#butAllChange, (winw-butw)/2, (winh-buth-stah)/2, butw, buth, "Change Status Bar Fields")
; Event loop AKJ 02-Sep-08
Define done.b=#False, ev
Dim fieldX(2)
Repeat
ev = WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
Select EventGadget()
Case #butAllChange
; Randomly choose status bar field widths (as x co-ordinates of field ends)
Repeat
fieldX(0) = Random(winw-200)+100
fieldX(1) = fieldX(0) + Random(winw-200)+100
Until fieldX(1)<=winw-100
fieldX(2) = -1 ; Fill remaining width
; See http://msdn.microsoft.com/en-us/library/bb760757(VS.85).aspx
SendMessage_(hsta, #SB_SETPARTS, 3, fieldX())
StatusBarText(#staBar, 0, "Width = "+Str(fieldX(0)))
StatusBarText(#staBar, 1, "Width = "+Str(fieldX(1)-fieldX(0)))
StatusBarText(#staBar, 2, "Width = "+Str(winw-fieldX(1)))
EndSelect
Case #PB_Event_CloseWindow
done = #True
EndSelect
Until done
End
I modified akj's code so that it doesn't use API. It seems to work fine, though I can't confirm this for Linux or MacOS.Progi1984 wrote:But the problem is the portability : How can you do this under Linux & MacOS ?
Code: Select all
; Demo of Changing Status Bar Field Widths AKJ 07-Sep-08
;modified by Demivec to use non - API
EnableExplicit
RandomSeed(ElapsedMilliseconds())
Enumeration
#winMain
#staBar
#butAllChange
EndEnumeration
Structure statusBar
width.l
text.s
EndStructure
Procedure setupStatusBar(hwin.l,fields.statusBar(1),numFields.l)
Protected field.l
If CreateStatusBar(#staBar, hwin)
For field = 0 To numFields - 1
AddStatusBarField(fields(field)\width)
StatusBarText(#staBar, field, fields(field)\text)
Next field
EndIf
EndProcedure
; Create GUI
Define winw, winh, flags, hwin, hsta, field, stah, butw, buth
winw = 500: winh = 200
butw = 160: buth = 30
flags = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered
hwin = OpenWindow(#winMain, 0, 0, winw, winh, " Adjust Status Bar Field Widths", flags)
Dim fieldX.statusBar(2)
For field = 0 To 2
fieldX(field)\width = winw/3
fieldX(field)\text = "Field "+Str(field)
Next
setupStatusBar(hwin,fieldX(),3)
stah = StatusBarHeight(#staBar)
CreateGadgetList(hwin)
ButtonGadget(#butAllChange, (winw-butw) / 2, (winh - buth - stah) / 2, butw, buth, "Change Status Bar Fields")
; Event loop AKJ 02-Sep-08
Define done.b = #False, ev
Repeat
ev = WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
Select EventGadget()
Case #butAllChange
; Randomly choose status bar field widths
Repeat
fieldX(0)\width = Random(winw - 200) + 100
fieldX(1)\width = Random(winw - 200) + 100
fieldX(2)\width = winw - fieldX(0)\width - fieldX(1)\width ; Fill remaining width
Until fieldX(2)\width>=100
fieldX(0)\text = "Width = " + Str(fieldX(0)\width)
fieldX(1)\text = "Width = " + Str(fieldX(1)\width)
fieldX(2)\text = "Width = " + Str(fieldX(2)\width)
SetupStatusBar(hwin,fieldX(),3)
EndSelect
Case #PB_Event_CloseWindow
done = #True
EndSelect
Until done
End
Code: Select all
; Event loop AKJ 02-Sep-08
Define done.b = #False, ev
Repeat
ev = WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
Select EventGadget()
Case #butAllChange
; Randomly choose status bar field widths
Repeat
fieldX(0)\width = Random(winw - 200) + 100
fieldX(1)\width = Random(winw - 200) + 100
fieldX(2)\width = winw - fieldX(0)\width - fieldX(1)\width ; Fill remaining width
Until fieldX(2)\width>=100
fieldX(0)\text = "Width = " + Str(fieldX(0)\width)
fieldX(1)\text = "Width = " + Str(fieldX(1)\width)
fieldX(2)\text = "Width = " + Str(fieldX(2)\width)
SetupStatusBar(hwin,fieldX(),3)
EndSelect
Case #PB_Event_CloseWindow
done = #True
EndSelect
Until done
End
Thanks, I had apparently overlooked some details in my hasty rewrite. I've edited the code in my post to reflect your revision.akj wrote:@Demivec
Your version is not reporting the status bar field widths correctly.
Here is revised code for the event loop to overcome that: