Page 1 of 1

Coloring StatusBar Items

Posted: Thu Sep 15, 2005 6:25 pm
by TerryHough
Search hasn't been my friend on this...

Is it possible to set the color of a statusbar item's background and/or text?

Nico posted a tip on this, but it doesn't handle the background. I modified
it thinking I could get it to work, but only partly sucessful.

I only get the background behind the text I sent colored, not the entire
item. Anybody know how to change the entire item's background color?

TIA
Terry

Posted: Thu Sep 15, 2005 9:13 pm
by GreenGiant
I've modified Nico's code a bit to show how to colour the background. I've not coloured individual items in this, but I think it should be easy enough to work out from this. Hope it helps.

Code: Select all

Global hBrush1
Global hBrush2
Global Hstatus

;THESE ARE THE TWO BACKGROUND COLOURS
hBrush1 = CreateSolidBrush_($FF0000)
hBrush2 = CreateSolidBrush_($00FF00)

Structure Status_Draw
  Texte.s
  couleur.l
  Font.l
  Emplacement.l
EndStructure

Procedure WindowCallback(WindowID, Message, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_DRAWITEM
      If wParam = GetDlgCtrlID_(Hstatus)
        *DrawItem.DRAWITEMSTRUCT = lParam
        *pointeur.Status_Draw=*DrawItem\itemData
        hFontOld = SelectObject_(*DrawItem\hDC,*pointeur\Font)
        SetBkMode_(*DrawItem\hDC, #TRANSPARENT)
        SetTextColor_(*DrawItem\hDC, *pointeur\couleur )
        
        ;THIS IS ADDED
        Stat.RECT
        GetWindowRect_(Hstatus,@Stat.RECT)
        Stat\right=Stat\right-Stat\left
        Stat\left=0
        Stat\bottom=Stat\bottom-Stat\top
        Stat\top=0
        FillRect_(*DrawItem\hDC,@Stat.RECT,hBrush1)
        ;UP TO HERE
        
        DrawText_(*DrawItem\hDC, *pointeur\Texte, -1, *DrawItem\rcItem , *pointeur\Emplacement)
        ProcedureReturn #True
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure 

  OpenWindow(0, 100, 150, 300, 100, #PB_Window_SystemMenu | #PB_Window_SizeGadget, "Status Bar")
  SetWindowCallback(@WindowCallback())
 
  Hstatus= CreateStatusBar(0, WindowID())
  SendMessage_(Hstatus, #SB_SETMINHEIGHT, 40, 0)
  SendMessage_(Hstatus, #WM_SIZE, 0,0)
  
  ;THIS IS ALSO ADDED
  SetClassLong_(Hstatus, #GCL_HBRBACKGROUND, hBrush2)
  InvalidateRect_(Hstatus, #NULL, #TRUE)
  ;UP TO HERE
 
  If Hstatus
    AddStatusBarField(100)
    AddStatusBarField(50)
    AddStatusBarField(100)
  EndIf
 
  Champ_0.Status_Draw
  Champ_0\Texte="Pierre"
  Champ_0\couleur=RGB(255,0,0)
  Champ_0\Font=hFont=LoadFont (0, "Courier", 20)
  Champ_0\Emplacement=#DT_CENTER| #DT_VCENTER| #DT_SINGLELINE
 
  Champ_1.Status_Draw
  Champ_1\Texte="Paul"
  Champ_1\couleur=RGB(0,168,168)
  Champ_1\Font=hFont=LoadFont (1, "Courier", 8)
  Champ_1\Emplacement=#DT_LEFT| #DT_BOTTOM| #DT_SINGLELINE
 
  Champ_2.Status_Draw
  Champ_2\Texte="Nico"
  Champ_2\couleur=RGB(255,255,255)
  Champ_2\Font=hFont=LoadFont (2, "Arial", 16)
  Champ_2\Emplacement=#DT_TOP|#DT_RIGHT| #DT_SINGLELINE
 
  *pointeur_champ0.Status_Draw=@Champ_0
  *pointeur_champ1.Status_Draw=@Champ_1
  *pointeur_champ2.Status_Draw=@Champ_2
 
  SendMessage_(Hstatus, #SB_SETTEXT, 0 | #SBT_OWNERDRAW ,*pointeur_champ0)
  SendMessage_(Hstatus, #SB_SETTEXT, 1 | #SBT_OWNERDRAW ,*pointeur_champ1)
  SendMessage_(Hstatus, #SB_SETTEXT, 2 | #SBT_OWNERDRAW ,*pointeur_champ2)

 
  Repeat
  Until WaitWindowEvent()=#PB_Event_CloseWindow

CloseFont(0)
CloseFont(1)
CloseFont(2)

;AND THESE ARE ADDED TOO
DeleteObject_(hBrush1)
DeleteObject_(hBrush2)

Posted: Thu Sep 15, 2005 10:01 pm
by TerryHough
Thanks GreenGiant,

I will give a study.

Terry