Hey, I have a ListView control in a dialog box that I want to have alternating row colours but obviously account for when a row is highlighted. This is my attempt so far but all I get is a blank looking listview, but I know the values are inside of it because the scrollbar appears.
Note: the listview control WAS created with the LVS_OWNERDRAWFIXED style.
case WM_DRAWITEM:
{
DRAWITEMSTRUCT* di;
di = (DRAWITEMSTRUCT*)lParam;
if ( di->CtlType == ODT_LISTVIEW )
{
di->rcItem;
HWND hItem;
hItem = (HWND) wParam;
RECT rcRow, rcClient;
rcRow = di->rcItem;
GetClientRect( hItem , &rcClient );
rcRow.right = rcClient.right;
HDC hDC = di->hDC;
if ( di->itemState == ODS_SELECTED )
{
SetTextColor( hDC , GetSysColor( COLOR_HIGHLIGHTTEXT ) );
SetBkColor ( hDC , GetSysColor( COLOR_HIGHLIGHT ) );
FillRect ( hDC , &rcRow , (HBRUSH) GetSysColor( COLOR_HIGHLIGHT ) );
}
else if ( di->itemState == ODS_DEFAULT )
{
SetTextColor( hDC , di->itemID % 2 == 1 ? GetSysColor( COLOR_WINDOWTEXT ) : GetSysColor( COLOR_MENUTEXT ) );
SetBkColor ( hDC , di->itemID % 2 == 1 ? GetSysColor( COLOR_WINDOW ) : GetSysColor( COLOR_MENU ) );
FillRect ( hDC , &rcRow , di->itemID % 2 == 1 ? (HBRUSH) GetSysColor( COLOR_WINDOW ) : (HBRUSH) GetSysColor( COLOR_MENU ) );
}
}
}
break;
Can you tell me if I'm going about it the right way or help to point out my errors. If I'm going way off the mark could you please point me in the direction of a tutorial on how to do it. Thanks.