See bold code. Replace
OnGetCellBkColor
and
OnGetCellTextColor
with your RGB values.
void CMyListView::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
ENSURE(pNMHDR != NULL);
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
switch (lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
{
int iColumn = lplvcd->iSubItem;
int iRow = (int) lplvcd->nmcd.dwItemSpec;
lplvcd->clrTextBk = OnGetCellBkColor(iRow, iColumn, lplvcd->nmcd.lItemlParam);
lplvcd->clrText = OnGetCellTextColor(iRow, iColumn, lplvcd->nmcd.lItemlParam);
if (iColumn == m_iSortedColumn && m_bMarkSortedColumn && lplvcd->clrTextBk == GetListCtrl().GetBkColor())
{
lplvcd->clrTextBk = m_clrSortedColumn;
}
HFONT hFont = OnGetCellFont( iRow, iColumn, lplvcd->nmcd.lItemlParam);
if (hFont != NULL)
{
m_hOldFont = (HFONT) SelectObject(lplvcd->nmcd.hdc, hFont);
ENSURE(m_hOldFont != NULL);
*pResult = CDRF_NEWFONT | CDRF_NOTIFYPOSTPAINT;
}
else
{
*pResult = CDRF_DODEFAULT;
}
}
break;
case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
if (m_hOldFont != NULL)
{
SelectObject(lplvcd->nmcd.hdc, m_hOldFont);
m_hOldFont = NULL;
}
*pResult = CDRF_DODEFAULT;
break;
}
}