Changeing ListIconGadget's Item-Select color
Changeing ListIconGadget's Item-Select color
I have got a little problem to struggle with:
Is it possible to change the color of a selected Item in a listview? On XP it's mostly black. If the gadget has not focus any more it's shown in a very light gray, nearly white. I also want to change this color. possible?
Is it possible to change the color of a selected Item in a listview? On XP it's mostly black. If the gadget has not focus any more it's shown in a very light gray, nearly white. I also want to change this color. possible?
Tranquil
*** Edit to fix bugs
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...
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
Last edited by Sparkie on Mon Aug 11, 2008 1:07 am, edited 3 times in total.
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
-
- Enthusiast
- Posts: 118
- Joined: Thu May 17, 2007 8:35 pm
- Location: USA
here's a small snippet of code from a project i am working on:Tranquil wrote:Thanks both of you. I hoped to came arround owner drawed items as I have dynamicly added listicongadgets with multiselection enabled on many MDI-Windows which does not make it easier.
Maybe I will use SetGadgetItemColor() to do this with some tricks.
If TotalFiles = MaxFiles
AddGadgetItem(7, TotalFiles-1, "REGISTER TO SEE MORE STUFF!")
SetGadgetItemColor(7,TotalFiles-1,#PB_Gadget_FrontColor,RGB(180,0,0) )
SetGadgetItemColor(7,TotalFiles-1,#PB_Gadget_BackColor,RGB(200,255,255) )
Else
AddGadgetItem(7, TotalFiles-1, FileEntry$)
SetGadgetItemColor(7,TotalFiles-1,#PB_Gadget_FrontColor,#Black)
SetGadgetItemColor(7,TotalFiles-1,#PB_Gadget_BackColor,RGB(255,255,255) )
endif
sets the color of a single item in the list. at least it works for me-
hope this helps-
best,
Mike