[Solved] Difficulties with StatusBar

Just starting out? Need help? Post your questions and find answers here.
ZX80
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 12, 2016 1:37 pm

[Solved] Difficulties with StatusBar

Post 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.
Last edited by ZX80 on Wed Nov 12, 2025 2:44 pm, edited 1 time in total.
User avatar
skywalk
Addict
Addict
Posts: 4262
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Difficulties with StatusBar

Post by skywalk »

The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
ZX80
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 12, 2016 1:37 pm

Re: Difficulties with StatusBar

Post 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.
Mesa
Enthusiast
Enthusiast
Posts: 460
Joined: Fri Feb 24, 2012 10:19 am

Re: Difficulties with StatusBar

Post 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.
ZX80
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 12, 2016 1:37 pm

Re: Difficulties with StatusBar

Post by ZX80 »

Mesa, thanks a lot !

Looks like this is what it takes !

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