StatusBar - Resize
StatusBar - Resize
It could be cool if we can resize a field of a statusbar.
Here's a way to do it in Windows:
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
Anthony Jordan
Read this: http://www.purebasic.fr/blog/?p=30
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

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 ?
The code simply recreates the StatusBar with the desired widths. The only method that is questionable is that it does not manually free the old status bar before creating the new one. I was thinking that if the same ID# was used it should free it before recreating it.
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
Last edited by Demivec on Tue Sep 09, 2008 8:33 am, edited 1 time in total.
@Demivec
Your version is not reporting the status bar field widths correctly.
Here is revised code for the event loop to overcome that:
Your version is not reporting the status bar field widths correctly.
Here is revised code for the event loop to overcome that:
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
Anthony Jordan