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