Page 1 of 1
[Solved] Get X pos and width of a StatusBar field?
Posted: Sun Jan 02, 2022 12:01 pm
by BarryG
Hi, trying to work out how to get the X position and width of a specific StatusBar field. Not sure, but thinking it's to do with #SB_GETPARTS, but I don't know. Can someone please help me out? Code template below to work with. Thanks!
Code: Select all
OpenWindow(0, 400, 200, 600, 100, "StatusBar", #PB_Window_SystemMenu)
sb=CreateStatusBar(0, WindowID(0))
AddStatusBarField(Random(200,70))
AddStatusBarField(Random(200,70)) : StatusBarText(0,1,"X/W of this")
AddStatusBarField(Random(200,70))
; Do the math here. :)
Debug "X of field 1 = "+Str(x)
Debug "W of field 1 = "+Str(w)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Get X pos and width of a StatusBar field?
Posted: Sun Jan 02, 2022 12:40 pm
by chi
Code: Select all
OpenWindow(0, 400, 200, 600, 100, "StatusBar", #PB_Window_SystemMenu)
sb=CreateStatusBar(0, WindowID(0))
AddStatusBarField(Random(200,70))
AddStatusBarField(Random(200,70)) : StatusBarText(0,1,"X/W of this")
AddStatusBarField(Random(200,70))
Debug SendMessage_(sb, #SB_GETPARTS, 0, 0) ;field count
; Do the math here. :)
SendMessage_(sb, #SB_GETRECT, 1, sbRect.RECT)
Debug "X of field 1 = "+Str(sbRect\left)
Debug "W of field 1 = "+Str(sbRect\right-sbRect\left)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Get X pos and width of a StatusBar field?
Posted: Sun Jan 02, 2022 12:56 pm
by BarryG
Thank you, Chi!
Just to show I was trying, here's part of my code that I was working on, which worked for each X position, and I was trying to get the widths next (which I assume I do by subtracting each new width from the previous in the array). I suck at basic math sometimes!
But your code is so much simpler, and doesn't need an array. Thank you again!
Code: Select all
Dim StatusBarFieldSize(5) ; Because my app has 5 StatusBar fields.
SendMessage_(statusbar,#SB_GETPARTS,5,@StatusBarFieldSize()) ; Get each field X pos into the array.
Re: [Solved] Get X pos and width of a StatusBar field?
Posted: Sun Jan 02, 2022 2:12 pm
by chi
If you only need the right edge of each field, you could use SB_GETPARTS like this...
Code: Select all
OpenWindow(0, 400, 200, 600, 100, "StatusBar", #PB_Window_SystemMenu)
sb=CreateStatusBar(0, WindowID(0))
AddStatusBarField(Random(200,70))
AddStatusBarField(Random(200,70)) : StatusBarText(0,1,"X/W of this")
AddStatusBarField(Random(200,70))
AddStatusBarField(#PB_Ignore)
count = SendMessage_(sb, #SB_GETPARTS, 0, 0)
Dim statbar.l(count-1)
SendMessage_(sb, #SB_GETPARTS, count, statbar())
For i=0 To count-1
Debug "field " + Str(i) + " re: " + statbar(i)
Next
Debug ""
; Do the math here. :)
SendMessage_(sb, #SB_GETRECT, 1, sbRect.RECT)
Debug "X of field 1 = "+Str(sbRect\left)
Debug "W of field 1 = "+Str(sbRect\right-sbRect\left)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow