Trying to alternate row colors in listview control but handle for selected items.
Message Loop of parent window (DialogBox)
//
case WM_NOTIFY:
{
// NOTE: g_hList is the ListView Control
// : hWnd is the parent of g_hList (Dialog Window)
if ( LOWORD( wParam ) == (WPARAM) ID_LIST )
{
LPNMLISTVIEW pnm;
pnm = (LPNMLISTVIEW)lParam;
if( pnm->hdr.hwndFrom == g_hList && pnm->hdr.code ==
NM_CUSTOMDRAW )
{
SetWindowLong( hWnd , DWL_MSGRESULT ,
(LONG)ProcessCustomDraw (lParam) );
return TRUE;
}
}
}
break;
Function to handle it..
LRESULT ProcessCustomDraw (LPARAM lParam)
{
int iRow;
LPNMLVCUSTOMDRAW pListDraw = (LPNMLVCUSTOMDRAW)lParam;
switch(pListDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
{
return (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW);
}
case CDDS_ITEMPREPAINT:
{
if ( pListDraw->nmcd.uItemState == CDIS_SELECTED )
{
pListDraw->clrText = GetSysColor( COLOR_HIGHLIGHTTEXT );
pListDraw->clrTextBk = GetSysColor( COLOR_HIGHLIGHT );
}
else
{
iRow = (int)pListDraw->nmcd.dwItemSpec;
pListDraw->clrText = iRow%2 == 0 ? GetSysColor( COLOR_WINDOWTEXT ) : GetSysColor( COLOR_MENUTEXT );
pListDraw->clrTextBk = iRow%2 == 0 ? GetSysColor( COLOR_WINDOW ) : GetSysColor( COLOR_MENU );
}
return CDRF_NEWFONT;
}
break;
default:
break;
}
return CDRF_DODEFAULT;
}
I just basically get a blank looking listbox, i.e. the items inside don't show up, but I know they are there because there is a scrollbar.
Thanks.