This is cut out from some old code of mine and could use a little TLC but it shows the basics.

Quickly tested and working on XP...
Code: Select all
#LVS_EX_CHECKBOXES = 4
;... Create brushes for painting item background
Structure MYBRUSHES
brushDefault.l
brushFocus.l
brushSelected.l
EndStructure
Global brush.MYBRUSHES
brush\brushSelected = CreateSolidBrush_(RGB(128, 255, 128))
brush\brushFocus = CreateSolidBrush_(RGB(200, 255, 200))
brush\brushDefault = GetStockObject_(#WHITE_BRUSH)
Procedure myWindowCallback(hwnd, msg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*nmhdr.NMHDR = lParam
*lvCD.NMLVCUSTOMDRAW = lParam
If *lvCD\nmcd\hdr\hwndFrom = GadgetID(0) And *lvCD\nmcd\hdr\code = #NM_CUSTOMDRAW
Select *lvCD\nmcd\dwDrawStage
Case #CDDS_PREPAINT
result = #CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT
result = #CDRF_NOTIFYSUBITEMDRAW;
Case #CDDS_ITEMPREPAINT | #CDDS_SUBITEM
thisRow = *lvCD\nmcd\dwItemSpec
thisCol = *lvCD\iSubItem
;... Draw checkboxes as needed
exStyle = SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
If thisCol = 0 And exStyle & #LVS_EX_CHECKBOXES
stateList = SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETIMAGELIST, #LVSIL_STATE, 0)
ckState = SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETITEMSTATE, thisRow, #LVIS_STATEIMAGEMASK) >>12 -1
checkRect.RECT\left = #LVIR_ICON
checkRect.RECT\top = 0
SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETITEMRECT, thisRow, @checkRect)
ImageList_Draw_(stateList, ckState, *lvCD\nmcd\hdc, 0, checkRect\top, #ILD_TRANSPARENT)
EndIf
;... Define rect for text
subItemRect.RECT\left = #LVIR_LABEL
subItemRect.RECT\top = *lvCD\iSubItem
;... Get the subitem rect
SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETSUBITEMRECT, thisRow, @subItemRect)
subItemText$ = GetGadgetItemText(0, thisRow, thisCol)
If GetGadgetItemState(*lvCD\nmcd\hdr\idFrom, thisRow) & #PB_ListIcon_Selected And GetFocus_() <> *lvCD\nmcd\hdr\hwndFrom
FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushFocus)
ElseIf GetGadgetItemState(*lvCD\nmcd\hdr\idFrom, thisRow) & #PB_ListIcon_Selected And GetFocus_() = *lvCD\nmcd\hdr\hwndFrom
FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushSelected)
Else
FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushDefault)
EndIf
;.. Set left margin
subItemRect\left + 3
DrawText_(*lvCD\nmcd\hdc, subItemText$, Len(subItemText$), subItemRect, #DT_WORD_ELLIPSIS | #DT_SINGLELINE | #DT_VCENTER)
result = #CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 480, 260, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@myWindowCallback())
ListIconGadget(0, 10, 10, 470, 225, "Column 0", 150, #PB_ListIcon_CheckBoxes | #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Column 1", 150)
For a = 0 To 9
addtext$ = "Column 0 Item " + Str(a) + Chr(10) + "Column 1 Item " + Str(a)
atLen = Len(addtext$)
AddGadgetItem(0,-1, addtext$)
Next
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
DeleteObject_(brush\brushSelected)
DeleteObject_(brush\brushFocus)
EndIf
End