Page 1 of 1

[Solved] Difficulties with StatusBar

Posted: Sat Nov 08, 2025 9:14 pm
by ZX80
Hello everyone again.

I also wanted to say that I am experiencing difficulties when working with StatusBar. Why can't I choose a font style for the StatusBar ? Maybe I missed something ?
I have to use this old code:

Code: Select all

; Title:  Custom Statusbar Text Colors
; Author: Fluid Byte
; Date:   December 28, 2006

Structure ODSBTEXT
   szText.l
   clrFront.l
EndStructure

Global font
font = LoadFont(#PB_Any, "FixedSys", 14)

Procedure WindowCallback(hWnd.l,uMsg.l,wParam.l,lParam.l)
    Select uMsg
        Case #WM_DRAWITEM
       *lpdis.DRAWITEMSTRUCT = lParam

      ClassName$ = Space(19) : GetClassName_(*lpdis\hwndItem,ClassName$,19)

      If ClassName$ = "msctls_statusbar32"
         *osbt.ODSBTEXT = *lpdis\itemData

         SelectObject_(*lpdis\hDC,FontID(font))
         SetTextColor_(*lpdis\hDC,*osbt\clrFront)
         ;SetBkColor_(*lpdis\hDC, #TRANSPARENT)
         SetBkMode_(*lpdis\hDC, #TRANSPARENT)

         SendMessage_(*lpdis\hwndItem,#SB_GETBORDERS,0,aBorders.RECT)
         InflateRect_(*lpdis\rcItem,-aBorders\right / 2,0)      
         DrawText_(*lpdis\hDC,*osbt\szText,-1,*lpdis\rcItem,#DT_SINGLELINE | #DT_VCENTER)
      EndIf
    EndSelect
     
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0,0,0,350,100,"Custom Statusbar Text Colors",#WS_OVERLAPPEDWINDOW | 1)

SetWindowCallback(@WindowCallback())

Result = CreateStatusBar(0,WindowID(0))

AddStatusBarField(100) : StatusBarText(0,0,"Statusbar Field #1") 
AddStatusBarField(100) : StatusBarText(0,1,"Statusbar Field #2")
AddStatusBarField(100)

osbt.ODSBTEXT
osbt\szText = @"Statusbar Field #3"
osbt\clrFront = #Black  
;osbt\clrBack = #Black

SendMessage_(Result,#SB_SETTEXT,2 | #SBT_OWNERDRAW,osbt)

While WaitWindowEvent() ! 16 : Wend
The default font is too small. When switching focus or minimizing a window, text disappears from the StatusBar fields. A similar issue was recently discussed here, but it didn't involve the StatusBar. I have to remember the state of each field and periodically update the contents of the StatusBar. This is very inconvenient. Moreover, it requires additional work to track events such as window minimization, overlapping with another window, etc. And still I couldn't get it to work properly. I also saw some great code from mk-soft (handmade StatusBar). I just saw this work recently. This is great, but it requires some code rework.
By the way... there was a trick here for getting text from any StatusBar field. So... It doesn't work with this code!
Could someone take a look at this code ? What could be causing this behavior ? I haven't seen any specific pattern.

Thanks in advance.

Re: Difficulties with StatusBar

Posted: Sat Nov 08, 2025 10:06 pm
by skywalk

Re: Difficulties with StatusBar

Posted: Sun Nov 09, 2025 8:23 am
by ZX80
skywalk, thanks for your reply !

I will consider your solution in more detail.

P.S. Such nuances and workarounds make interface development tedious and slow down the main work.
So I'd like to see native support for such basic features in future versions of PB. I hope so.
When you resize the window, you lose all the contents of the StatusBar. This is unacceptable. This comment refers to the old code I posted above. Need to update the StatusBar library is long overdue.

Fred, please take attention to this.

Re: Difficulties with StatusBar

Posted: Wed Nov 12, 2025 9:19 am
by Mesa
Maybe like that :

Code: Select all

LoadFont (1, "", 24)

If OpenWindow(0, 100, 150, 300, 100, "PureBasic - StatusBar Example", #PB_Window_SystemMenu | #PB_Window_SizeGadget)

   CreateStatusBar(0, WindowID(0))
   SendMessage_(StatusBarID(0), #WM_SETFONT, FontID(1),1)
   SendMessage_(StatusBarID(0), #SB_SETMINHEIGHT, 30, 0)
   SendMessage_(StatusBarID(0), #WM_SIZE, 0,0)
    AddStatusBarField(100)
    AddStatusBarField(100)
    AddStatusBarField(100)
 

  StatusBarText(0, 0, "Area 1")
  StatusBarText(0, 1, "Area 2")
  StatusBarText(0, 2, "Area 3")
     
  Repeat

  Until WaitWindowEvent() = #PB_Event_CloseWindow
 
EndIf 
M.

Re: Difficulties with StatusBar

Posted: Wed Nov 12, 2025 12:44 pm
by ZX80
Mesa, thanks a lot !

Looks like this is what it takes !

P.S. Yes, that's it! Thanks again!