Page 1 of 1

Scrollbar color

Posted: Wed Mar 16, 2005 2:09 am
by Hroudtwolf
Hello,

Is there a way to colorize a scrollbar from a explorertreegadget?

Posted: Thu Mar 17, 2005 4:18 am
by Sparkie
Short answer is no.

Long answer is to maybe disable ExplorerTreeGadget scrollbars and create your own, then set color during #WM_CTLCOLORSCROLLBAR.

I tried using the InitializeFlatSB_() API function, it sort of works but is very buggy on the ExplorerTreeGadget.

Posted: Thu Mar 17, 2005 2:37 pm
by Sparkie
Not sure I'd ever use this, but if you really need this feature, here's a quick and dirty example. This only handles the vertical scrollbar. If The ExplorerTreeGadget uses a horizontal scrollbar, you'll need to handle that as well. Also, you can only set the background color of the scrollbar, not the thumb or arrows. There's probably a way to do that, but you're on your own for that. ;)

Code: Select all

scrollBarWidth = GetSystemMetrics_(#SM_CXVSCROLL) 
Enumeration 
  #Win_Main 
EndEnumeration 

Enumeration 
  #Container_0 
  #ExplorerTree_0 
  #ScrollBar_0 
EndEnumeration 

;--> Create background brush for our ScrollBarGadget 
hSBbrush = CreateSolidBrush_(RGB(255, 0, 0)) 
;--> SCROLLINFO structure for getting / setting scroll positions 
sInfo.SCROLLINFO 
sInfo\cbSize = SizeOf(SCROLLINFO) 
sInfo\fMask = #SIF_PAGE | #SIF_POS | #SIF_RANGE | #SIF_TRACKPOS 
;--> Globals 
Global oldCallback, hSBbrush 
;--> Procedure to catch ScrollBarGadget messages 
Procedure.l mySBcallback(hwnd, msg, wparam, lparam) 
  result = CallWindowProc_(oldCallback, hwnd, msg, wparam, lparam) 
  Select msg 
    Case #WM_CTLCOLORSCROLLBAR 
      ;--> Set color for ScrollBar background 
      result = hSBbrush 
    Case #WM_VSCROLL 
      ;--> Get ScrollBarGadget position and relay to ExplorerTreeGadget 
      GetScrollInfo_(GadgetID(#ScrollBar_0), #SB_CTL, @sInfo) 
      SetScrollInfo_(GadgetID(#ExplorerTree_0), #SB_VERT, sInfo, 0) 
      SendMessage_(GadgetID(#ExplorerTree_0), #WM_VSCROLL, wparam, lparam) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
quit = #False 
If OpenWindow(#Win_Main, 0, 0, 600, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"ExplorerTreeGadget / Colored Scrollbar") And CreateGadgetList(WindowID(0)) 
  ;--> Put ExplorerTreeGadget inside a container to hide scrollbar 
  ;--> ExplorerTreeGadget width is 20 pixels wider than ContainerGadget 
  ;--> This hides the ExplorerTreeGadget's scrollbar 
  ContainerGadget(#Container_0, 10, 10, 563, 100) 
  ExplorerTreeGadget(#ExplorerTree_0, 0, 0, GadgetWidth(#Container_0) + scrollBarWidth + 2, GadgetHeight(#Container_0), "", #PB_Explorer_NoFiles) 
  CloseGadgetList() 
  ;--> Get current scrollbar info from ExplorerTreeGadget 
  GetScrollInfo_(GadgetID(#ExplorerTree_0), #SB_VERT, @sInfo) 
  ;--> Thenn send the info to our ScrollBarGadget 
  ScrollBarGadget(#ScrollBar_0, GadgetX(#Container_0) + GadgetWidth(#Container_0), 10, scrollBarWidth, 100, sInfo\nMin, sInfo\nMax, sInfo\nPage, #PB_ScrollBar_Vertical) 
  ;--> Subclass our ScrollBarGadget's parent to catch #WM_VSCROLL 
  oldCallback = SetWindowLong_(GetParent_(GadgetID(#ScrollBar_0)), #GWL_WNDPROC, @mySBcallback()) 
  Repeat 
    event = WaitWindowEvent() 
    Select event 
      ;--> Handle the Mousewheel
      Case #WM_MOUSEWHEEL
        If GetFocus_() = (GadgetID(#ExplorerTree_0))
          GetScrollInfo_(GadgetID(#ExplorerTree_0), #SB_VERT, @sInfo) 
          SetScrollInfo_(GadgetID(#ScrollBar_0), #SB_CTL, sInfo, 1) 
        EndIf
      Case #PB_EventGadget 
        Select EventGadgetID() 
          Case #ExplorerTree_0 
            ;--> Get any new scrollbar info if ExplorerTreeGadget is active 
            GetScrollInfo_(GadgetID(#ExplorerTree_0), #SB_VERT, @sInfo) 
            SetScrollInfo_(GadgetID(#ScrollBar_0), #SB_CTL, sInfo, 1) 
        EndSelect 
      Case #PB_Event_CloseWindow 
        ;--> Delete the brush we created earlier 
        DeleteObject_(hSBbrush) 
        quit = #True 
    EndSelect 
  Until quit = #True 
EndIf  

Posted: Thu Mar 17, 2005 3:06 pm
by Hroudtwolf
endless THX @ Sparkie

Posted: Thu Mar 17, 2005 4:08 pm
by Sparkie
You're welcome @Hroudtwolf :)