I´ve had the same/similar problem. I wanted to colorize the active Panel with OwnerDraw
Code: Select all
Import "Comctl32.lib"
; use the PureBasic Syntax (Windows API Functions using trailing underscore)
;
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
SetWindowSubclass_(hWnd, *fnSubclass, uIdSubclass, dwRefData) As "SetWindowSubclass"
GetWindowSubclass_(hWnd, *fnSubclass, uIdSubclass, *dwRefData) As "GetWindowSubclass"
RemoveWindowSubclass_(hWnd, *fnSubclass, uIdSubclass) As "RemoveWindowSubclass"
DefSubclassProc_(hWnd, uMsg, wParam, lParam) As "DefSubclassProc"
CompilerElse
SetWindowSubclass_(hWnd, *fnSubclass, uIdSubclass, dwRefData) As "_SetWindowSubclass@16"
GetWindowSubclass_(hWnd, *fnSubclass, uIdSubclass, *dwRefData) As "_GetWindowSubclass@16"
RemoveWindowSubclass_(hWnd, *fnSubclass, uIdSubclass) As "_RemoveWindowSubclass@12"
DefSubclassProc_(hWnd, uMsg, wParam, lParam) As "_DefSubclassProc@16"
CompilerEndIf
EndImport
#Window_Einstellung_Benutzer = 1
#Panel_Einstellungen_Benutzer = 10
#Panel_Option_2 = 11
#Text_HauptAnsicht = 20
#Checkbox_Hauptansicht = 21
#Combobox_hauptansicht = 22
; ---------------------------------------------------------------------------------------------------------------------
; SubclasssWindowProc .. (all in one)
; ---------------------------------------------------------------------------------------------------------------------
Define hBrushStatic
Procedure SubclassWindowProc(hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData)
Shared hBrushStatic
Protected bkcolor
Select uMsg
Case #WM_NCDESTROY
RemoveWindowSubclass_(hWnd, @SubclassWindowProc(), uIdSubclass) ; return is non-zero if successful
Case #WM_CTLCOLORSTATIC
SetTextColor_(wParam, #Black)
bkcolor = GetSysColor_(#COLOR_BTNFACE)
;bkcolor = GetSysColor_(#COLOR_INFOBK)
SetBkColor_(wParam, bkcolor)
If hBrushStatic = #Null
hBrushStatic = CreateSolidBrush_(bkcolor)
EndIf
ProcedureReturn hBrushStatic
Case #WM_DESTROY
DeleteObject_(hBrushStatic) ; not needed with GetSysColorBrush_(), but with CreateSolidBrush_()
Case #WM_DRAWITEM
Protected *drawItem.DRAWITEMSTRUCT
Protected text.s, textColor, brush
*drawItem = lParam ; type cast :)
;
; here we can use uIdSubclass (assigned #Panel_Einstellungen_Benutzer)
;
If wParam = uIdSubclass
If *drawItem\itemID <> -1 And *drawItem\CtlType = #ODT_TAB
text = GetGadgetItemText(wParam, *drawItem\itemID)
brush = CreateSolidBrush_(GetSysColor_(#COLOR_3DFACE))
If (*drawItem\itemState & #ODS_SELECTED) <> 0 ; for the selected tab we use RED
textColor = #Red
Else
textColor = GetSysColor_(#COLOR_WINDOWTEXT)
EndIf
FillRect_(*drawItem\hdc, *drawItem\rcItem, brush)
DeleteObject_(brush) ; no longer needed
SetTextColor_(*drawItem\hdc, textColor)
SetBkMode_(*drawItem\hdc, #TRANSPARENT)
DrawText_(*drawItem\hdc, @text, Len(text), *drawItem\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER | #DT_NOCLIP)
;TextOut_(*drawItem\hdc, *drawItem\rcItem\left+2, *drawItem\rcItem\top, @text, Len(text))
ProcedureReturn 0
EndIf
EndIf ; wParam = uIdSubclass
EndSelect
ProcedureReturn DefSubclassProc_(hWnd, uMsg, wParam, lParam)
EndProcedure
If OpenWindow(#Window_Einstellung_Benutzer, 0, 0, 720,400, "Einstellungen",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
PanelGadget(#Panel_Einstellungen_Benutzer,0,0,720,350)
SetWindowLong_(GadgetID(#Panel_Einstellungen_Benutzer), #GWL_STYLE, GetWindowLong_(GadgetID(#Panel_Einstellungen_Benutzer), #GWL_STYLE) | #TCS_OWNERDRAWFIXED)
SetWindowSubclass_(WindowID(#Window_Einstellung_Benutzer), @SubclassWindowProc(), #Panel_Einstellungen_Benutzer, 0)
AddGadgetItem(#Panel_Einstellungen_Benutzer,-1,"Auswertung")
AddGadgetItem(#Panel_Einstellungen_Benutzer,-1,"Ansicht")
PanelGadget(#Panel_Option_2,0,0,600,250)
SetWindowLong_(GadgetID(#Panel_Option_2), #GWL_STYLE, GetWindowLong_(GadgetID(#Panel_Option_2), #GWL_STYLE) | #TCS_OWNERDRAWFIXED)
SetWindowSubclass_(GetParent_(GadgetID(#Panel_Option_2)), @SubclassWindowProc(), #Panel_Option_2, 0)
AddGadgetItem(#Panel_Option_2,-1,"TEST")
AddGadgetItem(#Panel_Option_2,-1,"noch ein Test")
TextGadget(#Text_HauptAnsicht,10,20,100,24,"Vollauswertung")
SetWindowSubclass_(GetParent_(GadgetID(#Text_HauptAnsicht)), @SubclassWindowProc(), 0, 0)
CheckBoxGadget(#checkbox_Hauptansicht,10,50,100,24,"CHECK IT")
ComboBoxGadget(#Combobox_Hauptansicht,10,80,100,24)
AddGadgetItem(#Combobox_Hauptansicht,-1,"Auswahl 1")
AddGadgetItem(#Combobox_Hauptansicht,-1,"Auswahl 2")
AddGadgetItem(#Combobox_Hauptansicht,-1,"Auswahl 3")
SetGadgetState(#Combobox_hauptansicht,1)
CloseGadgetList() ; <-- this should be added
CloseGadgetList()
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf