I have been looking at this for a little while now, and just can't work out how I change this code so that I can use it to highlight in a different colour.
If I wanted to specify a colour using RBG, how do I insert it into the code below?
$include "windowssdk.inc"
$include "commctrl.inc"
$define SUBCLASS1_ID 12345 ' any number
CONST LISTBOX_1 = 1000
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80CB0080,0,"Caption",&d1_handler
CONTROL d1,@LISTBOX,"ListBox1",13,10,173,175,0x50A10140|LBS_OWNERDRAWFIXED,LISTBOX_1
DOMODAL d1
end
SUB d1_handler(),int
SELECT @MESSAGE
CASE @IDINITDIALOG
SetWindowSubclass(d1.hwnd, &MySubclassProc, SUBCLASS1_ID, 0)
CENTERWINDOW d1
OnInitDialog()
CASE @IDCLOSEWINDOW
RemoveWindowSubclass(d1.hwnd, &MySubclassProc, SUBCLASS1_ID)
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE LISTBOX_1
/* respond to control notifications here */
ENDSELECT
ENDSELECT
RETURN 0
ENDSUB
sub OnInitDialog()
' add some string, saving its indexes
int x
for x=1 to 20
ADDSTRING d1, LISTBOX_1, "item"+str$(x)
next x
endsub
sub MySubclassProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam,UINT_PTR uIdSubclass,DWORD_PTR dwRefData)
select (uMsg)
case WM_DRAWITEM
if( (*<DRAWITEMSTRUCT>lParam.CtlType = ODT_LISTBOX) _
and (*<DRAWITEMSTRUCT>lParam.CtlID = LISTBOX_1) _
and (*<DRAWITEMSTRUCT>lParam.itemID >= 0))
' Erase item background
if *<DRAWITEMSTRUCT>lParam.itemID = 4 'Highlighted entry............
FillRect(*<DRAWITEMSTRUCT>lParam.hDC, &*<DRAWITEMSTRUCT>lParam.rcItem, _
GetSysColorBrush(IIF(*<DRAWITEMSTRUCT>lParam.itemState & ODS_SELECTED, _
COLOR_HIGHLIGHT,12)))
else
FillRect(*<DRAWITEMSTRUCT>lParam.hDC, &*<DRAWITEMSTRUCT>lParam.rcItem, _
GetSysColorBrush(IIF(*<DRAWITEMSTRUCT>lParam.itemState & ODS_SELECTED, _
COLOR_HIGHLIGHT, COLOR_WINDOW)))
endif
' any text to draw?
HWND hwndListbox = *<DRAWITEMSTRUCT>lParam.hwndItem
' number of characters
int cchText = _SendMessage(hwndListbox, LB_GETTEXTLEN, *<DRAWITEMSTRUCT>lParam.itemID, 0)
if (cchText)
' get the string
pointer pText = new(TCHAR, cchText+1)
_SendMessage(hwndListbox, LB_GETTEXT, *<DRAWITEMSTRUCT>lParam.itemID, pText)
' setup text coordinates, equal to *<DRAWITEMSTRUCT>lParam.rcItem
WINRECT rc
CopyRect(&rc, &*<DRAWITEMSTRUCT>lParam.rcItem)
UINT bkMode = SetBkMode(*<DRAWITEMSTRUCT>lParam.hDC, TRANSPARENT)
DrawText(*<DRAWITEMSTRUCT>lParam.hDC, pText, cchText, &rc, DT_SINGLELINE|DT_VCENTER)
SetBkMode(*<DRAWITEMSTRUCT>lParam.hDC, bkMode)
delete pText
endif
' do not forward this message to default handlers, we handled it
return 0
endif
endselect
return DefSubclassProc(hWnd, uMsg, wParam, lParam)
endsub
See if this is what you are looking for
http://www.ionicwind.com/forums/index.php?topic=4986.msg37948#msg37948
Thanks Larry,
Missed that post - that's exactly what I'm after!
Andy.