Posted: Sat Oct 13, 2007 3:41 am
Let me see what I can come with. 

http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Enumeration
#WindowMain=1
EndEnumeration
Enumeration
#ListIcon1=1
#Button1
EndEnumeration
#LVM_GETSUBITEMRECT=#LVM_FIRST+56
#CDDS_ITEM=$10000
#CDDS_POSTERASE=4
#CDDS_POSTPAINT=2
#CDDS_PREERASE=3
#CDDS_PREPAINT=1
#CDDS_ITEMPOSTERASE=#CDDS_ITEM|#CDDS_POSTERASE
#CDDS_ITEMPOSTPAINT=#CDDS_ITEM|#CDDS_POSTPAINT
#CDDS_ITEMPREERASE=#CDDS_ITEM|#CDDS_PREERASE
#CDDS_ITEMPREPAINT=#CDDS_ITEM|#CDDS_PREPAINT
#CDDS_SUBITEM=$20000
#CDRF_DODEFAULT=0
#CDRF_NOTIFYITEMDRAW=$20
#CDRF_NOTIFYPOSTERASE=$40
#CDRF_NOTIFYPOSTPAINT=$10
#CDRF_NOTIFYSUBITEMDRAW=$20
#CDRF_SKIPDEFAULT=4
Procedure GetCharWidth(hListIcon,char$)
ProcedureReturn SendMessage_(hListIcon,#LVM_GETSTRINGWIDTH,0,@char$)
EndProcedure
Procedure WinCallback(hwnd,msg,wparam,lparam)
result=#PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*nmhdr.NMHDR=lparam
If *nmhdr\code=#NM_CUSTOMDRAW And *nmhdr\hwndFrom=GadgetID(#ListIcon1)
*lvCD.NMLVCUSTOMDRAW=lparam
SetBkMode_(*lvCD\nmcd\hdc,#TRANSPARENT)
Select *lvCD\nmcd\dwDrawStage
Case #CDDS_PREPAINT
result=#CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT
result=#CDRF_NOTIFYSUBITEMDRAW
Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
result=#CDRF_NOTIFYPOSTPAINT
Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM
If *lvCD\nmcd\dwItemSpec>-1 And *lvCD\iSubItem>-1
item$=GetGadgetItemText(#ListIcon1,*lvCD\nmcd\dwItemSpec,*lvCD\iSubItem)
subItemRc.RECT\left=#LVIR_LABEL : subItemRc\top=*lvCD\iSubItem
SendMessage_(*lvCD\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*lvCD\nmcd\dwItemSpec,@subItemRc)
For char=1 To Len(item$)
zz=#Black : If (char>7 And char<12) Or (char>16 And char<22) : zz=#Red : EndIf
char$=Mid(item$,char,1) : SetTextColor_(*lvCD\nmcd\hdc,zz) : DrawText_(*lvCD\nmcd\hdc,char$,1,subItemRc,#DT_NOCLIP)
subItemRc\left+GetCharWidth(*nmhdr\hwndFrom,char$) + *lvCD\nmcd\dwItemSpec + *lvCD\iSubItem
Next char
EndIf
result=#CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(#WindowMain,200,200,620,235,"Sparkies Multicolor ListIconGadget",#PB_Window_SystemMenu) And CreateGadgetList(WindowID(#WindowMain))
SetWindowCallback(@WinCallback())
ListIconGadget(#ListIcon1,5,5,610,195,"Column 0",270,#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect)
AddGadgetItem(#ListIcon1,-1,"I want THIS and THIS to be red")
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Code: Select all
SendMessage_(GadgetID(#ListIcon1), #LVM_SETTEXTCOLOR, 0, #White)
Code: Select all
Enumeration
#WindowMain=1
EndEnumeration
Enumeration
#ListIcon1=1
#Button1
EndEnumeration
#LVM_GETSUBITEMRECT=#LVM_FIRST+56
#CDDS_ITEM=$10000
#CDDS_POSTERASE=4
#CDDS_POSTPAINT=2
#CDDS_PREERASE=3
#CDDS_PREPAINT=1
#CDDS_ITEMPOSTERASE=#CDDS_ITEM|#CDDS_POSTERASE
#CDDS_ITEMPOSTPAINT=#CDDS_ITEM|#CDDS_POSTPAINT
#CDDS_ITEMPREERASE=#CDDS_ITEM|#CDDS_PREERASE
#CDDS_ITEMPREPAINT=#CDDS_ITEM|#CDDS_PREPAINT
#CDDS_SUBITEM=$20000
#CDRF_DODEFAULT=0
#CDRF_NOTIFYITEMDRAW=$20
#CDRF_NOTIFYPOSTERASE=$40
#CDRF_NOTIFYPOSTPAINT=$10
#CDRF_NOTIFYSUBITEMDRAW=$20
#CDRF_SKIPDEFAULT=4
Procedure GetCharWidth(hListIcon,char$)
ProcedureReturn SendMessage_(hListIcon,#LVM_GETSTRINGWIDTH,0,@char$)
EndProcedure
Procedure WinCallback(hwnd,msg,wParam,lParam)
result=#PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*nmhdr.NMHDR=lParam
If *nmhdr\code=#NM_CUSTOMDRAW And *nmhdr\hwndFrom=GadgetID(#ListIcon1)
*lvCD.NMLVCUSTOMDRAW=lParam
SetBkMode_(*lvCD\nmcd\hdc,#TRANSPARENT)
Select *lvCD\nmcd\dwDrawStage
Case #CDDS_PREPAINT
result=#CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT
If *lvCD\nmcd\dwItemSpec>-1 And *lvCD\iSubItem>-1
item$=GetGadgetItemText(#ListIcon1,*lvCD\nmcd\dwItemSpec,*lvCD\iSubItem)
subItemRc.RECT\left=#LVIR_LABEL : subItemRc\top=*lvCD\iSubItem
SendMessage_(*lvCD\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*lvCD\nmcd\dwItemSpec,@subItemRc)
For Char=1 To Len(item$)
zz=#Black : If (Char>7 And Char<12) Or (Char>16 And Char<22) : zz=#Red : EndIf
char$=Mid(item$,Char,1) : SetTextColor_(*lvCD\nmcd\hdc,zz) : DrawText_(*lvCD\nmcd\hdc,char$,1,subItemRc,#DT_NOCLIP)
subItemRc\left+GetCharWidth(*nmhdr\hwndFrom,char$) + *lvCD\nmcd\dwItemSpec + *lvCD\iSubItem
Next Char
EndIf
result=#CDRF_SKIPDEFAULT;#CDRF_NOTIFYSUBITEMDRAW
Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
result=#CDRF_NOTIFYPOSTPAINT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(#WindowMain,200,200,620,235,"Sparkies Multicolor ListIconGadget",#PB_Window_SystemMenu) And CreateGadgetList(WindowID(#WindowMain))
SetWindowCallback(@WinCallback())
ListIconGadget(#ListIcon1,5,5,610,195,"Column 0",270,#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect)
AddGadgetItem(#ListIcon1,-1,"I want THIS and THIS to be red")
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Code: Select all
SendMessage_(GadgetID(#ListIcon1), #LVM_SETTEXTCOLOR, 0, #White)
Code: Select all
Enumeration
#WindowMain=1
EndEnumeration
Enumeration
#ListIcon1=1
#Button1
EndEnumeration
#LVM_GETSUBITEMRECT=#LVM_FIRST+56
#CDDS_ITEM=$10000
#CDDS_POSTERASE=4
#CDDS_POSTPAINT=2
#CDDS_PREERASE=3
#CDDS_PREPAINT=1
#CDDS_ITEMPOSTERASE=#CDDS_ITEM|#CDDS_POSTERASE
#CDDS_ITEMPOSTPAINT=#CDDS_ITEM|#CDDS_POSTPAINT
#CDDS_ITEMPREERASE=#CDDS_ITEM|#CDDS_PREERASE
#CDDS_ITEMPREPAINT=#CDDS_ITEM|#CDDS_PREPAINT
#CDDS_SUBITEM=$20000
#CDRF_DODEFAULT=0
#CDRF_NOTIFYITEMDRAW=$20
#CDRF_NOTIFYPOSTERASE=$40
#CDRF_NOTIFYPOSTPAINT=$10
#CDRF_NOTIFYSUBITEMDRAW=$20
#CDRF_SKIPDEFAULT=4
Procedure GetCharWidth(hListIcon,char$)
ProcedureReturn SendMessage_(hListIcon,#LVM_GETSTRINGWIDTH,0,@char$)
EndProcedure
Procedure WinCallback(hwnd,msg,wParam,lParam)
result=#PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*nmhdr.NMHDR=lParam
If *nmhdr\code=#NM_CUSTOMDRAW And *nmhdr\hwndFrom=GadgetID(#ListIcon1)
*lvCD.NMLVCUSTOMDRAW=lParam
SetBkMode_(*lvCD\nmcd\hdc,#TRANSPARENT)
Select *lvCD\nmcd\dwDrawStage
Case #CDDS_PREPAINT
result=#CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT
result=#CDRF_NOTIFYSUBITEMDRAW
Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
result=#CDRF_NOTIFYPOSTPAINT
Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM
If *lvCD\nmcd\dwItemSpec>-1 And *lvCD\iSubItem>-1
item$=GetGadgetItemText(#ListIcon1,*lvCD\nmcd\dwItemSpec,*lvCD\iSubItem)
subItemRc.RECT\left=#LVIR_LABEL : subItemRc\top=*lvCD\iSubItem
SendMessage_(*lvCD\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*lvCD\nmcd\dwItemSpec,@subItemRc)
subItemRc\left + 2
For Char=1 To Len(item$)
zz=#Black : If (Char>7 And Char<12) Or (Char>16 And Char<22) : zz=#Red : EndIf
char$=Mid(item$,Char,1) : SetTextColor_(*lvCD\nmcd\hdc,zz) : DrawText_(*lvCD\nmcd\hdc,char$,1,subItemRc,#DT_NOCLIP)
subItemRc\left+GetCharWidth(*nmhdr\hwndFrom,char$) + *lvCD\nmcd\dwItemSpec + *lvCD\iSubItem
Next Char
EndIf
result=#CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(#WindowMain,200,200,620,235,"Sparkies Multicolor ListIconGadget",#PB_Window_SystemMenu) And CreateGadgetList(WindowID(#WindowMain))
SetWindowCallback(@WinCallback())
ListIconGadget(#ListIcon1,5,5,610,195,"Column 0",270,#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect)
AddGadgetItem(#ListIcon1,-1,"I want THIS and THIS to be red")
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Code: Select all
; //////////////////////////////////////////
Code: Select all
; ...................................................
Code: Select all
Procedure GetCharWidth(gad,c$)
ProcedureReturn SendMessage_(gad,#LVM_GETSTRINGWIDTH,0,@c$)
EndProcedure
Procedure WinCallback(hwnd,msg,wParam,lParam)
result=#PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*nmhdr.NMHDR=lParam
If *nmhdr\code=#NM_CUSTOMDRAW And *nmhdr\hwndFrom=GadgetID(0)
*lvCD.NMLVCUSTOMDRAW=lParam
Select *lvCD\nmcd\dwDrawStage
Case #CDDS_ITEMPREPAINT
result=#CDRF_NOTIFYSUBITEMDRAW
Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
result=#CDRF_NOTIFYPOSTPAINT
Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM
If *lvCD\nmcd\dwItemSpec>-1 And *lvCD\iSubItem>-1
item$=GetGadgetItemText(0,*lvCD\nmcd\dwItemSpec,*lvCD\iSubItem)
subItemRc.RECT\left=#LVIR_LABEL : subItemRc\top=*lvCD\iSubItem
SendMessage_(*lvCD\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*lvCD\nmcd\dwItemSpec,@subItemRc)
subItemRc\left+2
For c=1 To Len(item$)
zz=#Black : If (c>7 And c<12) Or (c>16 And c<22) : zz=#Red : EndIf
c$=Mid(item$,c,1) : SetTextColor_(*lvCD\nmcd\hdc,zz) : DrawText_(*lvCD\nmcd\hdc,c$,1,subItemRc,#DT_NOCLIP)
subItemRc\left+GetCharWidth(*nmhdr\hwndFrom,c$) + *lvCD\nmcd\dwItemSpec + *lvCD\iSubItem
Next
EndIf
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0,200,200,620,235,"Sparkies Multicolor ListIconGadget",#PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
SetWindowCallback(@WinCallback())
ListIconGadget(0,5,5,610,195,"Column 0",270,#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect)
AddGadgetItem(0,-1,"I want THIS and THIS to be red")
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Code: Select all
Procedure GetCharWidth(gad,c$)
ProcedureReturn SendMessage_(gad,#LVM_GETSTRINGWIDTH,0,@c$)
EndProcedure
Procedure WinCallback(hwnd,msg,wParam,lParam)
result=#PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*nmhdr.NMHDR=lParam
If *nmhdr\code=#NM_CUSTOMDRAW And *nmhdr\hwndFrom=GadgetID(0)
*lvCD.NMLVCUSTOMDRAW=lParam
Select *lvCD\nmcd\dwDrawStage
Case #CDDS_ITEMPREPAINT
result=#CDRF_NOTIFYSUBITEMDRAW
Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
result=#CDRF_SKIPDEFAULT
If *lvCD\nmcd\dwItemSpec>-1 And *lvCD\iSubItem>-1
item$=GetGadgetItemText(0,*lvCD\nmcd\dwItemSpec,*lvCD\iSubItem)
subItemRc.RECT\left=#LVIR_LABEL : subItemRc\top=*lvCD\iSubItem
SendMessage_(*lvCD\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*lvCD\nmcd\dwItemSpec,@subItemRc)
If GetGadgetState(0)<>*lvCD\nmcd\dwItemSpec
FillRect_(*lvCD\nmcd\hdc, subItemRc, GetStockObject_(#WHITE_BRUSH))
Else
hBrush = CreateSolidBrush_(GetSysColor_(#COLOR_HIGHLIGHT))
FillRect_(*lvCD\nmcd\hdc, subItemRc, hBrush)
DeleteObject_(hBrush)
EndIf
For c=1 To Len(item$)
zz=#Black : If (c>7 And c<12) Or (c>16 And c<22) : zz=#Red : EndIf
c$=Mid(item$,c,1) : SetTextColor_(*lvCD\nmcd\hdc,zz) : DrawText_(*lvCD\nmcd\hdc,c$,1,subItemRc,#DT_NOCLIP)
subItemRc\left+GetCharWidth(*nmhdr\hwndFrom,c$) + *lvCD\iSubItem
Next
EndIf
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0,200,200,620,235,"Sparkies Multicolor ListIconGadget",#PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
SetWindowCallback(@WinCallback())
ListIconGadget(0,5,5,610,195,"Column 0",270,#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(0,1,"ll",110)
AddGadgetItem(0,-1,"I want THIS and THIS to be red"+Chr(10)+"kk")
AddGadgetItem(0,-1,"I want THIS and THIS to be red")
AddGadgetItem(0,-1,"I want THIS and THIS to be red")
AddGadgetItem(0,-1,"I want THIS and THIS to be red")
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
...knowing that you'll need to repair all the damage done by that idiot srod when you return!Sparkie wrote:I still can't remember why I handled this in the post paint process.I thought this code was based on my multiline item ListIconGadget code, which handles all drawing, including selected and focused items, in pre-paint and post-paint process.
I'm on my way out to walk the dog so I'll let srod take over whilst I'm gone