Page 1 of 2
coloring status bar text
Posted: Thu Dec 28, 2006 6:18 pm
by purebuilt
Hi all,
How do you change the text color of one tab or section of your status bar text?
Thanks.
Posted: Thu Dec 28, 2006 7:53 pm
by Tranquil
A code snipped can be found in the purearea code-archive. but it seems not to be possible just to colorize one tab. only the complete statusbar.

and even this does not work under all OS Versions.
Re: coloring status bar text
Posted: Thu Dec 28, 2006 9:06 pm
by Fluid Byte
purebuilt wrote:How do you change the text color of one tab or section of your status bar text?
Simple, you can't natively. Only option is to specify one or more owner-draw field parts:
Code: Select all
; Title: Custom Statusbar Text Colors
; Author: Fluid Byte
; Date: December 28, 2006
Structure ODSBTEXT
szText.l
clrFront.l
clrBack.l
EndStructure
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
SetTextColor_(*lpdis\hDC,*osbt\clrFront)
SetBkColor_(*lpdis\hDC,*osbt\clrBack)
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 = #Green
osbt\clrBack = #Black
SendMessage_(Result,#SB_SETTEXT,2 | #SBT_OWNERDRAW,osbt)
While WaitWindowEvent() ! 16 : Wend
Re: coloring status bar text
Posted: Sun Oct 04, 2009 1:38 pm
by zoot33
In the above code, how could you centre the text within an owner drawn status area ?
Thanks
Re: coloring status bar text
Posted: Sun Oct 04, 2009 2:05 pm
by Fluid Byte
Just add the #DT_CENTER flag to the DrawText_() command.
Re: coloring status bar text
Posted: Sun Oct 04, 2009 5:45 pm
by zoot33
Thanks a lot Fluid
Re: coloring status bar text
Posted: Thu Jul 19, 2018 4:43 pm
by Lord
Hi!
I know, this is an old posting, but I need some help here:
I tried to make a procedure from the above code.
The original code works, after changing
szText.l to
szText.i in structure ODBSTEXT.
So this is not my problem I got.
When moving the needed code part into a procedure, there is no text "3" in field #2.
I modified the code a bit to show the problem.
Just run my code first with Test=#True. There is a red "3" in field #2.
Now change Test to #False in order to run the code in the procedure.
There is no text in field 2.
What did I miss? Here is the code:
Code: Select all
; Title: Custom Statusbar Text Colors
; Author: Fluid Byte
; Date: December 28, 2006
Structure ODSBTEXT
szText.i; changed from .l to .i otherwise there is an IMA on DrawText_()
clrFront.l
clrBack.l
EndStructure
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
SetTextColor_(*lpdis\hDC, *osbt\clrFront)
SetBkColor_(*lpdis\hDC, *osbt\clrBack)
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 | #DT_RIGHT)
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure myStatusBarText(Field, Text.s, fCol, bCol)
Text+" "
osbt.ODSBTEXT
osbt\szText = @Text
osbt\clrFront = fCol
osbt\clrBack = bCol
SendMessage_(Result,#SB_SETTEXT, Field | #SBT_OWNERDRAW, osbt)
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, "1", #PB_StatusBar_Right)
AddStatusBarField(100) : StatusBarText(0, 1, "2", #PB_StatusBar_Right)
AddStatusBarField(100) :
Test=#True; <--- Change here to #False to see the the difference
Text.s="3"
Field=2
fCol.l=#Red
bCol.l=$F1EDED
If Test=#False
myStatusBarText(Field, Text, fCol, bCol)
Else
Text+" "
osbt.ODSBTEXT
osbt\szText = @Text
osbt\clrFront = fCol
osbt\clrBack = bCol
SendMessage_(Result,#SB_SETTEXT, Field | #SBT_OWNERDRAW, osbt)
EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Re: coloring status bar text
Posted: Thu Jul 19, 2018 5:39 pm
by ccode
Hello Lord,
The variable "Result" is unknown in your procedure.
Try this:
Code: Select all
; Title: Custom Statusbar Text Colors
; Author: Fluid Byte
; Date: December 28, 2006
Global Result ; Look here
Structure ODSBTEXT
szText.i; changed from .l to .i otherwise there is an IMA on DrawText_()
clrFront.l
clrBack.l
EndStructure
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
SetTextColor_(*lpdis\hDC, *osbt\clrFront)
SetBkColor_(*lpdis\hDC, *osbt\clrBack)
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 | #DT_RIGHT)
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure myStatusBarText(Field, Text.s, fCol, bCol)
Text+" "
osbt.ODSBTEXT
osbt\szText = @Text
osbt\clrFront = fCol
osbt\clrBack = bCol
SendMessage_(Result,#SB_SETTEXT, Field | #SBT_OWNERDRAW, osbt)
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, "1", #PB_StatusBar_Right)
AddStatusBarField(100) : StatusBarText(0, 1, "2", #PB_StatusBar_Right)
AddStatusBarField(100) :
Test=#False; <--- Change here to #False to see the the difference
Text.s="3"
Field=2
fCol.l=#Red
bCol.l=$F1EDED
If Test=#False
myStatusBarText(Field, Text, fCol, bCol)
Else
Text+" "
osbt.ODSBTEXT
osbt\szText = @Text
osbt\clrFront = fCol
osbt\clrBack = bCol
SendMessage_(Result,#SB_SETTEXT, Field | #SBT_OWNERDRAW, osbt)
EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Re: coloring status bar text
Posted: Fri Jul 20, 2018 10:15 am
by Lord
Hi ccode!
ccode wrote:...
The variable "Result" is unknown in your procedure.
...
That's it!
Thank you for pointing this out.
Re: coloring status bar text
Posted: Sun Jul 22, 2018 7:17 pm
by Lord
Sorry for disturbing again.
I still have a problem with coloring the text in a statusbar field.
The above shown code works...
...until you try to resize the window by dragging the bottom right corner.
When doing so, there is an IMA at
Code: Select all
DrawText_(*lpdis\hDC, *osbt\szText, -1, *lpdis\rcItem, #DT_SINGLELINE | #DT_VCENTER | #DT_RIGHT)
in the window callback.
*osbt\szText gets an value of 11 there. No valid pointer to text anymore.
Somebody any ideas?
Re: coloring status bar text
Posted: Tue Jul 24, 2018 9:52 am
by Lord
Hi!
The problem with field #3 is still there.
Even when replacing *osbt\szText with @"3 " in WindowCallback()
Code: Select all
DrawText_(*lpdis\hDC, @"3 ", -1, *lpdis\rcItem, #DT_SINGLELINE | #DT_VCENTER | #DT_RIGHT)
or defining a variable Text.s="3 " and replacing *osbt\szText with @Text
Code: Select all
Protected Text.s="3 "
DrawText_(*lpdis\hDC, @Text, -1, *lpdis\rcItem, #DT_SINGLELINE | #DT_VCENTER | #DT_RIGHT)
the field #3 in statusbar has still only a black rectangle when resizing the window.
But in this two variants the IMA is gone.
I know, Rashad has posted a canvas based solution:
viewtopic.php?f=12&t=71093
and I could use this, but I want to know, what went wrong here.
Re: coloring status bar text
Posted: Tue Jul 24, 2018 11:53 am
by RASHAD
Hi Lord
;Posted by Lord
;Modified by RASHAD
Code: Select all
; Title: Custom Statusbar Text Colors
; Author: Fluid Byte
; Date: December 28, 2006
Structure ODSBTEXT
szText.s; changed from .l to .i otherwise there is an IMA on DrawText_()
clrFront.i
clrBack.i
EndStructure
Global Result,osbt.ODSBTEXT
Procedure WindowCallback(hWnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_DRAWITEM
*lpdis.DRAWITEMSTRUCT = lParam
ClassName$ = Space(19) : GetClassName_(*lpdis\hwndItem, ClassName$,19)
If ClassName$ = "msctls_statusbar32"
*osbt.ODSBTEXT = *lpdis\itemData
SetTextColor_(*lpdis\hDC, *osbt\clrFront)
SetBkColor_(*lpdis\hDC, *osbt\clrBack)
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 | #DT_RIGHT)
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure myStatusBarText(Field, Text.s, fCol, bCol)
Text+" "
osbt.ODSBTEXT
osbt\szText = Text
osbt\clrFront = fCol
osbt\clrBack = bCol
SendMessage_(Result,#SB_SETTEXT, Field | #SBT_OWNERDRAW, osbt)
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, "1", #PB_StatusBar_Right)
AddStatusBarField(100) : StatusBarText(0, 1, "2", #PB_StatusBar_Right)
AddStatusBarField(100) :
Test=0; <--- Change here to #False to see the the difference
Text.s="3"
Field=2
fCol.l=#Red
bCol.l=$F1EDED
If Test=#False
myStatusBarText(Field, Text, fCol, bCol)
Else
Text+" "
osbt.ODSBTEXT
osbt\szText = Text
osbt\clrFront = fCol
osbt\clrBack = bCol
SendMessage_(Result,#SB_SETTEXT, Field | #SBT_OWNERDRAW, osbt)
EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
More control :
Code: Select all
; Title: Custom Statusbar Text Colors
; Author: Fluid Byte
; Date: December 28, 2006
Structure ODSBTEXT
szText.s; changed from .l to .i otherwise there is an IMA on DrawText_()
clrFront.i
;clrBack.i
hBrush.i
EndStructure
Global Result
Global Dim osbt.ODSBTEXT(5)
Procedure WindowCallback(hWnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_DRAWITEM
If wParam = GetDlgCtrlID_(Result)
*lpdis.DRAWITEMSTRUCT = lParam
*osbt.ODSBTEXT = *lpdis\itemData
SetTextColor_(*lpdis\hDC, *osbt\clrFront)
SetBkMode_(*lpdis\hDC, #TRANSPARENT)
;SetBkColor_(*lpdis\hDC, *osbt\clrBack)
FillRect_(*lpdis\hDC, *lpdis\rcItem, *osbt\hBrush)
;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 | #DT_RIGHT)
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure myStatusBarText(Field, Text.s, fCol, bCol)
Text+" "
osbt(Field)\szText = Text
osbt(Field)\clrFront = fCol
osbt(Field)\hBrush = CreateSolidBrush_(bCol)
SendMessage_(Result,#SB_SETTEXT, Field | #SBT_OWNERDRAW, osbt(Field))
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, "1", #PB_StatusBar_Right)
AddStatusBarField(100); : StatusBarText(0, 1, "2", #PB_StatusBar_Right)
AddStatusBarField(100); :
SendMessage_(Result, #SB_SETMINHEIGHT, 40, 0)
SendMessage_(Result, #WM_SIZE, 0,0)
Test=0; <--- Change here to #False to see the the difference
Text.s="1"
Field=0
fCol.l=#Green
bCol.l=#Gray
myStatusBarText(Field, Text, fCol, bCol)
Text.s="2"
Field=1
fCol.l=#Yellow
bCol.l=#Blue
myStatusBarText(Field, Text, fCol, bCol)
Text.s="3"
Field=2
fCol.l=#Red
bCol.l=#Yellow
myStatusBarText(Field, Text, fCol, bCol)
; If Test=#False
; myStatusBarText(Field, Text, fCol, bCol)
; Else
; Text+" "
; osbt.ODSBTEXT
; osbt\szText = Text
; osbt\clrFront = fCol
; osbt\clrBack = bCol
; SendMessage_(Result,#SB_SETTEXT, Field | #SBT_OWNERDRAW, osbt)
; EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Edit :Bugs fixed for PB x64
Re: coloring status bar text
Posted: Tue Jul 24, 2018 4:44 pm
by Lord
Hi Rashad!
Thank you for looking at this problem.
The good news is:
The first code you posted is working stand alone as it should.
The bad news are:
If incorporated in my existing code, the your first example
always gives me a red "BZ" without trailing spaces.
Inside WindowsCallback() the text @**osbt\szText has changed.
The second code shows a statusbar of almost doubled height
and with no text in any field.
Thank you for your help, but I'm giving up on this.
This is a issue for you experts, but not for me.
Re: coloring status bar text
Posted: Tue Jul 24, 2018 5:20 pm
by Kwai chang caine
Thanks RASHAD works like a charm

Re: coloring status bar text
Posted: Wed Jul 25, 2018 12:42 pm
by Lord
Kwai chang caine wrote:Thanks RASHAD works like a charm

That's interesting.
May I ask what Windows and what PB version you used to test?
I had in the just the chance to test the second version of Rashads code
on a Win81.1 with PB5.60(x64) while my sytem now is Win7, PB5.70(x64)beta.
On these the same result: not working.