GetStatusBarText

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

GetStatusBarText

Post by BarryG »

Would love to see this added, please. So we can get the text from any given StatusBar field. Thanks for considering.
Ventural
User
User
Posts: 31
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa, FL
Contact:

Re: GetStatusBarText

Post by Ventural »

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
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: GetStatusBarText

Post by BarryG »

Thank you, Ventural. A nice method until it becomes a native command. :)
User avatar
mk-soft
Always Here
Always Here
Posts: 6205
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetStatusBarText

Post by mk-soft »

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
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetStatusBarText

Post by jacdelad »

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
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: GetStatusBarText

Post by BarryG »

mk-soft wrote: Mon Mar 10, 2025 9:29 amWhy should you read the Statusbar text
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).
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
By that logic, SetWindowTitle() shouldn't need a corresponding GetWindowTitle() either, since it also has no user input. ;)
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: GetStatusBarText

Post by skywalk »

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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Quin
Addict
Addict
Posts: 1126
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: GetStatusBarText

Post by Quin »

+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.
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: GetStatusBarText

Post by BarryG »

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.
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GetStatusBarText

Post by infratec »

StatusBar stuff is GUI stuff.
So it should be only modified in the main EventLoop.

PostEvents() should be used to do this.
Quin
Addict
Addict
Posts: 1126
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: GetStatusBarText

Post by Quin »

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.
Sure, I agree.
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 ;)
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GetStatusBarText

Post by infratec »

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.
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetStatusBarText

Post by jacdelad »

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
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: GetStatusBarText

Post by BarryG »

infratec wrote: Thu Mar 13, 2025 9:14 pmWhy I need a function to get a text when I wrote it?
By that logic, PureBasic should remove GetWindowTitle(), GetGadgetText(), GetGadgetItemText(), GetGadgetData()... after all, we wrote them all.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: GetStatusBarText

Post by skywalk »

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
Post Reply