Restored from previous forum. Originally posted by Justin.
This code shows how to handle an ownerdraw listicon (list mode), to have different colors with each item.
My initial goal was to have a listicon in report mode with different colors for each subitem, but i'm having problems with it, any help would be appreciated:
http://msdn.microsoft.com/library/en-us ... stdraw.asp
Code: Select all
;Custom draw ListView
#LVS_OWNERDRAWFIXED=1024
#NM_CUSTOMDRAW=#NM_FIRST-12
#CDDS_ITEM=65536
#CDDS_PREPAINT=1
;#CDDS_ITEMPREPAINT=#CDDS_ITEM|#CDDS_PREPAINT
#CDRF_NOTIFYITEMDRAW=32
#CDRF_NEWFONT=2
Procedure listproc(hwnd,msg,wparam,lparam)
ret=#PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*ptr.NMLVCUSTOMDRAW=lparam
Select *ptr\nmcd\hdr\code
Case #NM_CUSTOMDRAW
Select *ptr\nmcd\dwDrawStage
Case #CDDS_PREPAINT
ret=#CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEM | #CDDS_PREPAINT
;set text color
*ptr\clrText=RGB(Random(255),Random(255),Random(255))
ret=#CDRF_NEWFONT
EndSelect
EndSelect
EndSelect
ProcedureReturn ret
EndProcedure
hWnd=OpenWindow(0,10,10,500,500,"Custom Draw List View",#PB_Window_SystemMenu)
hl=ListIconGadget(1,10,10,400,400,"",100,#PB_ListIcon_GridLines|#LVS_OWNERDRAWFIXED)
SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, 2)
ButtonGadget(2, 20, 450, 50, 20,"Add")
SetWindowCallback(@listproc())
Repeat
eid=WaitWindowEvent()
If eid=#PB_Event_Gadget
Select EventGadget()
Case 2
AddGadgetItem(1,-1,"Customdrawing!")
EndSelect
EndIf
Until eid=#PB_Event_CloseWindow