I mean that by OR'ing LVS_OWNERDRAWFIXED into your ListIconGadget style, you take over full responsibility for all drawing of the gadget. You have full control over colors, fonts, sizes, the works. Here's an example which does what you're asking for. Study it and you will see it's easy to go from where it is to choosing colors, fonts, even images for each individual cell. Anyway here it is:
Code: Select all
; Yet another useless program from netmaestro
Global oldproc, currentitem = -1, WhiteBrush = CreateSolidBrush_(#White)
LoadFont(0, "verdana", 10)
LoadFont(1, "verdana", 10, #PB_Font_Underline)
Procedure MainWindowCallBack(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_DRAWITEM
*lpdis.DRAWITEMSTRUCT = lparam
Dim itemrect.RECT(1)
For i = 0 To 1
RtlZeroMemory_(@itemrect(i),SizeOf(RECT))
itemrect(i)\top = i
SendMessage_(*lpdis\hwndItem, #LVM_GETSUBITEMRECT, *lpdis\itemid, @itemrect(i)) ; Get the specific subitem rectangle we're drawing to
text$ = GetGadgetItemText(*lpdis\CtlID, *lpdis\itemid, i) ; Get the text to write from the gadget
SelectObject_(*lpdis\hDC, GetStockObject_(#NULL_PEN))
SelectObject_(*lpdis\hDC, WhiteBrush) ; Choose a background color
With itemrect(i)
Rectangle_(*lpdis\hDC, \left+4, \top+4, \right, \bottom) ; Fill the rectangle with it
EndWith
If *lpdis\itemid = currentitem And i=0 ; Is the mouse on the item? (i=0 only underlines first column)
SelectObject_(*lpdis\hDc, FontID(1)) ; If yes, choose the underlined font
Else
SelectObject_(*lpdis\hDc, FontID(0)) ; If no, choose the normal font
EndIf
TextOut_(*lpdis\hDC, itemrect(i)\left+4, itemrect(i)\top+4, text$, Len(text$)) ; Draw the text in the chosen font
Next
Case #WM_MEASUREITEM
*lpmis.MEASUREITEMSTRUCT = lparam
*lpmis\itemheight = 20
EndSelect
ProcedureReturn result
EndProcedure
Procedure SubClass_LV(hwnd, msg, wparam, lparam)
If msg = #WM_MOUSEMOVE
GetCursorPos_(@cp.POINT)
MapWindowPoints_(0,hwnd,@cp,1)
HitInfo.LVHITTESTINFO
Hitinfo\pt\x = cp\x
HitInfo\pt\y = cp\y
SendMessage_(hwnd, #LVM_HITTEST , 0, @HitInfo)
thisitem = HitInfo\iItem
If thisitem <> currentitem
currentitem=thisitem
InvalidateRect_(hwnd, 0, 1)
EndIf
EndIf
ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure
OpenWindow(0,0,0,320,240,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowCallback(@MainWindowCallBack())
ListIconGadget(0,0,0,320,240,"FirstName",100,#PB_ListIcon_GridLines|#LVS_OWNERDRAWFIXED)
oldproc = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @SubClass_LV())
AddGadgetColumn(0,1,"LastName",100)
AddGadgetItem(0, -1, "Lloyd" + Chr(10) + "Gallant" )
AddGadgetItem(0, -1, "Eric" + Chr(10) + "Penrose" )
AddGadgetItem(0, -1, "Mark" + Chr(10) + "Dutton" )
AddGadgetItem(0, -1, "Tim" + Chr(10) + "Knechtel" )
Repeat : EventID = WaitWindowEvent() : Until EventID = #PB_Event_CloseWindow
Just remember that if you go this route, things like SetGadgetFont, SetGadgetItemColor, etc. aren't going to have any effect because you've assumed control of virtually all drawing decisions. SetGadgetItemText will still work fine.