Code: Alles auswählen
Global oldCallback
Structure color
backcolor.l
forecolor.l
EndStructure
Procedure SetPanelColor(id,state,color)
Protected *c.color
*c = GetWindowLong_(GadgetID(id),#GWL_USERDATA)
If Not *c
*c = AllocateMemory(SizeOf(color))
*c\backcolor = GetSysColor_(#COLOR_MENU)
*c\forecolor = GetSysColor_(#COLOR_WINDOWTEXT)
EndIf
If state = 1
*c\backcolor = color
ElseIf state = 2
*c\forecolor = color
EndIf
SetWindowLong_(GadgetID(id),#GWL_USERDATA,*c)
SetWindowPos_(GadgetID(id),0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE|#SWP_FRAMECHANGED|#SWP_NOZORDER)
EndProcedure
;...Our subclassed PanelGadget events
Procedure myPGcallback(hwnd, msg, wParam, lParam)
Protected *c.color
Protected bc,fc
Protected backbrush
result = CallWindowProc_(oldCallback, hwnd, msg, wParam, lParam)
Select msg
Case #WM_DRAWITEM
*PGdis.DRAWITEMSTRUCT = lParam
If *PGdis\CtlType = #ODT_TAB
*c.color = GetWindowLong_(*PGdis\hwndItem,#GWL_USERDATA)
If Not *c
bc = GetSysColor_(#COLOR_MENU)
fc = GetSysColor_(#COLOR_WINDOWTEXT)
Else
bc = *c\backcolor
fc = *c\forecolor
EndIf
backbrush = CreateSolidBrush_(bc)
Select *PGdis\itemState
Case #ODS_SELECTED
tabText$ = GetGadgetItemText(*PGdis\ctlid, *PGdis\itemID, 0)
FillRect_(*PGdis\hdc, *PGdis\rcItem, backbrush)
SetTextColor_(*PGdis\hdc, fc)
SetBkMode_(*PGdis\hdc, #TRANSPARENT)
DrawText_(*PGdis\hdc, tabText$, Len(tabText$), *PGdis\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER | #DT_NOCLIP)
Default
tabText$ = GetGadgetItemText(*PGdis\ctlid, *PGdis\itemID, 0)
SetTextColor_(*PGdis\hdc, 0)
SetBkMode_(*PGdis\hdc, #TRANSPARENT)
DrawText_(*PGdis\hdc, tabText$, Len(tabText$), *PGdis\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER | #DT_NOCLIP)
EndSelect
DeleteObject_(backbrush)
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 322, 280,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
PanelGadget(0, 8, 8, 306, 203)
AddGadgetItem (0, -1, "Panel 1")
ButtonGadget(1, 10, 30, 50, 20, "Hello")
AddGadgetItem (0, -1,"Panel 2")
ButtonGadget(2, 10, 30, 50, 20, "World")
AddGadgetItem (0, -1,"Panel 3")
ButtonGadget(3, 10, 30, 80, 20, "PureBasic")
CloseGadgetList()
ScrollBarGadget(4,5,230,310,20,0,$FFFFFF,1)
ScrollBarGadget(5,5,250,310,20,0,$FFFFFF,1)
; Ownderdraw and subcalss PanelGadget to colorize tabs
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE) | #TCS_OWNERDRAWFIXED)
oldCallback = SetWindowLong_(GetParent_(GadgetID(0)), #GWL_WNDPROC, @myPGcallback())
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = 4
SetPanelColor(0,1,GetGadgetState(4))
EndIf
If EventGadget() = 5
SetPanelColor(0,2,GetGadgetState(5))
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
End
auf das Loeschen des Speichers verzichtet.

