coloring status bar text
coloring status bar text
Hi all,
How do you change the text color of one tab or section of your status bar text?
Thanks.
How do you change the text color of one tab or section of your status bar text?
Thanks.
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: coloring status bar text
Simple, you can't natively. Only option is to specify one or more owner-draw field parts:purebuilt wrote:How do you change the text color of one tab or section of your status bar text?
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
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Re: coloring status bar text
In the above code, how could you centre the text within an owner drawn status area ?
Thanks
Thanks
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: coloring status bar text
Just add the #DT_CENTER flag to the DrawText_() command.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Re: coloring status bar text
Thanks a lot Fluid
Re: coloring status bar text
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:
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
Hello Lord,
The variable "Result" is unknown in your procedure.
Try this:
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
Hi ccode!
Thank you for pointing this out.
That's it!ccode wrote:...
The variable "Result" is unknown in your procedure.
...

Thank you for pointing this out.

Re: coloring status bar text
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 atin the window callback.
*osbt\szText gets an value of 11 there. No valid pointer to text anymore.
Somebody any ideas?

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)
*osbt\szText gets an value of 11 there. No valid pointer to text anymore.
Somebody any ideas?

Re: coloring status bar text
Hi!
The problem with field #3 is still there.
Even when replacing *osbt\szText with @"3 " in WindowCallback()
or defining a variable Text.s="3 " and replacing *osbt\szText with @Text
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.
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)
Code: Select all
Protected Text.s="3 "
DrawText_(*lpdis\hDC, @Text, -1, *lpdis\rcItem, #DT_SINGLELINE | #DT_VCENTER | #DT_RIGHT)
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
Hi Lord
;Posted by Lord
;Modified by RASHAD
More control :
Edit :Bugs fixed for PB x64
;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
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
Last edited by RASHAD on Wed Jul 25, 2018 1:03 pm, edited 1 time in total.
Egypt my love
Re: coloring status bar text
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.
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.

- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: coloring status bar text
Thanks RASHAD works like a charm 


Not a destination
Re: coloring status bar text
That's interesting.Kwai chang caine wrote:Thanks RASHAD works like a charm
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.
