
Relatively easy to do in Editor/Scintilla gadgets, but has anyone achieved the same for a ListIcon? Does it require kilometers of code?
Edit: Or changing the text colour would be good, à la Android.
Code: Select all
; Owner draw listview for the purpose of selective styling
; Lloyd Gallant (netmaestro) December 2016
Global search$ = "TIM"
Procedure MainWindowCallBack(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_DRAWITEM
*lpdis.DRAWITEMSTRUCT = lparam
Dim itemrect.RECT(3)
For i = 1 To 3
RtlZeroMemory_(@itemrect(i), SizeOf(RECT))
With itemrect(i)
\top = i
\left = #LVIR_BOUNDS
EndWith
SendMessage_(*lpdis\hwndItem, #LVM_GETSUBITEMRECT, *lpdis\itemid, @itemrect(i))
text$ = GetGadgetItemText(GetDlgCtrlID_(*lpdis\hwndItem), *lpdis\itemid, i)
loc = FindString(text$, search$, 1, #PB_String_NoCase)
If loc > 0
found$ = Mid(text$, loc, Len(search$))
If loc > 1
leftside$ = Left(text$, loc-1)
Else
leftside$ = ""
EndIf
GetTextExtentPoint32_(*lpdis\hDC, leftside$, Len(leftside$), @sz.SIZE)
start = sz\cx + 2
GetTextExtentPoint32_(*lpdis\hDC, found$, Len(found$), @sz.SIZE)
searchwidth = sz\cx
height = sz\cy
SetRect_(highlight.RECT, start+itemrect(i)\left, itemrect(i)\top+3, start+itemrect(i)\left+searchwidth, itemrect(i)\top+height)
Else
start=0
EndIf
If *lpdis\itemState & #ODS_SELECTED
hbrBackground = CreateSolidBrush_(GetSysColor_(#COLOR_HIGHLIGHT))
FillRect_(*lpdis\hdc, itemrect(i), hbrBackground)
DrawFocusRect_(*lpdis\hdc, itemrect(i))
SetTextColor_(*lpdis\hdc, GetSysColor_(#COLOR_HIGHLIGHTTEXT))
Else
hbrBackground = CreateSolidBrush_(GetSysColor_(#COLOR_WINDOW))
FillRect_(*lpdis\hdc, itemrect(i), hbrBackground)
If start
hbrHighlight = CreateSolidBrush_(RGB(255,255,0))
FillRect_(*lpdis\hdc, highlight, hbrHighlight)
DeleteObject_(hbrHighlight)
EndIf
SetTextColor_(*lpdis\hdc, GetSysColor_(#COLOR_WINDOWTEXT))
EndIf
DeleteObject_(hbrBackground)
SetBkMode_(*lpdis\hDC, #TRANSPARENT)
TextOut_(*lpdis\hDC, itemrect(i)\left+2, itemrect(i)\top+2, text$, Len(text$))
Next
Case #WM_MEASUREITEM
*lpmis.MEASUREITEMSTRUCT = lparam
*lpmis\itemheight = 20
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowCallback(@MainWindowCallBack())
ListIconGadget(0,0,0,320,240,"",0,#PB_ListIcon_GridLines|#LVS_OWNERDRAWFIXED)
AddGadgetColumn(0,1,"FirstName",100)
AddGadgetColumn(0,2,"LastName",100)
AddGadgetColumn(0,3,"City",115)
AddGadgetItem(0, -1, Chr(10) + "Lloyd" + Chr(10) + "Gallant" + Chr(10) + "Barrie" )
AddGadgetItem(0, -1, Chr(10) + "Mortimer" + Chr(10) + "Penrose" + Chr(10) + "Kitchener" )
AddGadgetItem(0, -1, Chr(10) + "Mark" + Chr(10) + "Dutton" + Chr(10) + "Guelph" )
AddGadgetItem(0, -1, Chr(10) + "Timothy" + Chr(10) + "Knechtel" + Chr(10) + "East Timmins")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow