Posted: Sun Jun 11, 2006 7:38 pm
You either have to use 'owner drawn' methods or what is called 'custom draw'.
In the code below, I use the easier of the two (custom draw) to alternate red text, blue background and blue text, red background etc.
I've put some checks in for button states etc.
Hope it helps.
In the code below, I use the easier of the two (custom draw) to alternate red text, blue background and blue text, red background etc.
I've put some checks in for button states etc.
Code: Select all
;Coloured header control.
;By srod.
;Purebasic 4.
;Windows.
#LVM_GETHEADER = #LVM_FIRST + 31
; Globals
Global oldListIconCallback, hHeader, redbrush, bluebrush
redbrush=CreateSolidBrush_(#Red)
bluebrush=CreateSolidBrush_(#Blue)
; Proc for subclassed ListIconGadget
Procedure SubclassedListIcon(hwnd, msg, wparam, lparam)
Protected hdi.hd_item
result = CallWindowProc_(oldListIconCallback, hwnd, msg, wparam, lparam)
Select msg
Case #WM_NOTIFY
*pnmh.NMHDR = lparam
;--> Get handle to ListIcon header control
If *pnmh\code = #NM_CUSTOMDRAW
*pnmcd.NMCUSTOMDRAW = lparam
;--> Determine drawing stage
Select *pnmcd\dwDrawStage
Case #CDDS_PREPAINT
result = #CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT
;Get header text.
text$=Space(100)
hdi\mask = #HDI_TEXT
hdi\psztext = @text$
hdi\cchtextmax = Len(text$)
SendMessage_(hHeader, #HDM_GETITEM,*pnmcd\dwItemSpec,hdi)
;Check button state.
If *pnmcd\uItemState & #CDIS_SELECTED
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH|#DFCS_PUSHED)
;Offset text because of the selected button.
InflateRect_(*pnmcd\rc,-1,-1)
Else
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
EndIf
;Draw background.
;Here we alternate red text on blue background.
InflateRect_(*pnmcd\rc,-1,-1)
SetBkMode_(*pnmcd\hdc,#TRANSPARENT)
If *pnmcd\dwItemSpec&1
FillRect_(*pnmcd\hdc, *pnmcd\rc, redbrush)
SetTextColor_(*pnmcd\hdc, #Blue)
Else
FillRect_(*pnmcd\hdc, *pnmcd\rc, bluebrush)
SetTextColor_(*pnmcd\hdc, #Red)
EndIf
DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc, #DT_CENTER|#DT_VCENTER|#DT_END_ELLIPSIS)
result = #CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
; ************************************************
; Main Window
; ************************************************
If OpenWindow(0, 100, 100, 415, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
ListIconGadget(0, 5, 5, 405, 200, "col 0", 50, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
hHeader = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
;Subclass ListIcon so we can customdraw the header text
oldListIconCallback = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @SubclassedListIcon())
;Add 10 more columns.
For i = 1 To 10
AddGadgetColumn(0, i, "col "+Str(i), 50)
Next
;Add some data
For b=0 To 99; Add 100 rows.
AddGadgetItem(0,-1,"")
Next
For i = 0 To 99
For j = 0 To 50
SetGadgetItemText(0,i,Str(i+j),j)
Next j
Next i
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
DeleteObject_(redbrush)
DeleteObject_(bluebrush)
EndIf
End