Scrollbar color
Posted: Wed Mar 16, 2005 2:09 am
Hello,
Is there a way to colorize a scrollbar from a explorertreegadget?
Is there a way to colorize a scrollbar from a explorertreegadget?
http://www.purebasic.com
https://www.purebasic.fr/english/
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