GetStatusBarText
GetStatusBarText
Would love to see this added, please. So we can get the text from any given StatusBar field. Thanks for considering.
Re: GetStatusBarText
Retrieves text from Statusbar fields.
Code: Select all
Procedure.s GetStatusbarText(StatusBarNum.q, FieldNum.l)
Define buffer.s = Space(256)
Define result.l = SendMessage_(StatusBarID(StatusBarNum), #SB_GETTEXT, FieldNum, @buffer)
Define length.l = result & $FFFF
ProcedureReturn Left(buffer, length)
;To remove extra spacing, change to: Trim(Left(buffer, length), Chr(9))
EndProcedure
If OpenWindow(0, 0, 0, 440, 50, "StatusBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
If CreateStatusBar(0, WindowID(0))
AddStatusBarField(90)
AddStatusBarField(100)
AddStatusBarField(#PB_Ignore)
AddStatusBarField(100)
EndIf
StatusBarText(0, 0, "Area normal")
StatusBarText(0, 1, "Area borderless", #PB_StatusBar_BorderLess)
StatusBarText(0, 2, "Area right", #PB_StatusBar_Right)
StatusBarText(0, 3, "Area centered", #PB_StatusBar_Center)
; Debug output for all fields
Debug "Field 0: " + GetStatusbarText(0, 0) ; "Area normal"
Debug "Field 1: " + GetStatusbarText(0, 1) ; "Area borderless"
Debug "Field 2: " + GetStatusbarText(0, 2) ; "Area right"
Debug "Field 3: " + GetStatusbarText(0, 3) ; "Area centered"
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: GetStatusBarText
Thank you, Ventural. A nice method until it becomes a native command. 

Re: GetStatusBarText
Why should you read the Statusbar text. Makes no sense to me as there is no user input here and it is only written.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: GetStatusBarText
It does, especially from foreign windows. I needed this on my previous workplace.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: GetStatusBarText
Because my app puts dynamic text there from multiple threads that changes every few seconds; so there's no point in me keeping track of the constant changes when a quick and simple "GetStatusBarText" command could just be used on demand instead. It's less resources and app maintenance for me if I had it (no need to set a Global variable from 20+ threads, plus any new threads that I might add later).
The other reason is because for every "Set" command, there really should be a corresponding "Get" command. Gadgets have them, so why not the StatusBar (rhetorical).
By that logic, SetWindowTitle() shouldn't need a corresponding GetWindowTitle() either, since it also has no user input.mk-soft wrote: Mon Mar 10, 2025 9:29 amMakes no sense to me as there is no user input here and it is only written

Re: GetStatusBarText
I love the statusbar for user updating and interaction. It is valuable real estate, so why not fully utilize?
That said, I prefer owner drawn statusbar as a containergadget of stringgadgets. Then, you control full behavior; color, font, resizing, mouse clock events, etc. And it becomes cross platform without custom API calls.
That said, I prefer owner drawn statusbar as a containergadget of stringgadgets. Then, you control full behavior; color, font, resizing, mouse clock events, etc. And it becomes cross platform without custom API calls.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: GetStatusBarText
+1, I've needed this in my app before, which is quite similar to Barry's in that the status bar is updated every few seconds from one of multiple threads, even sometimes more frequently if the user moves around a lot, and being able to programatically get the text would be super handy.
Re: GetStatusBarText
You can programmatically use a StatusBar as interactive with user input anyway. Example: in my app, clicking one of its fields toggles what it shows.
Re: GetStatusBarText
StatusBar stuff is GUI stuff.
So it should be only modified in the main EventLoop.
PostEvents() should be used to do this.
So it should be only modified in the main EventLoop.
PostEvents() should be used to do this.
Re: GetStatusBarText
Sure, I agree.infratec wrote: Thu Mar 13, 2025 4:43 pm StatusBar stuff is GUI stuff.
So it should be only modified in the main EventLoop.
PostEvents() should be used to do this.
Now, would you mind telling me what this has to do with adding a GetStatusBarText function? Regardless of how the info is set, we should be able to get it. To use Barry's earlier example once again, window titles can be gotten programmatically

Re: GetStatusBarText
Why I need a function to get a text when I wrote it?
If it is done at one place, you always know what is in the field.
Simply store it in a variable before you apply it like:
StatusBarField1$, StatusBarField2$, ...
But sure you can request every functionality you want.
And I never use GetWindowTitle(), it is faster to have it in a variable.
If it is done at one place, you always know what is in the field.
Simply store it in a variable before you apply it like:
StatusBarField1$, StatusBarField2$, ...
But sure you can request every functionality you want.
And I never use GetWindowTitle(), it is faster to have it in a variable.
Re: GetStatusBarText
What if you use a foreign module which changes/sets the titjebar if a certain window and you need to read it? In my opinion, if possible (!), every set function should have a get function.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: GetStatusBarText
By that logic, PureBasic should remove GetWindowTitle(), GetGadgetText(), GetGadgetItemText(), GetGadgetData()... after all, we wrote them all.
Re: GetStatusBarText
It depends if your user entered the data or you displayed read only status messages.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum