NM_CUSTOMDRAW 메시지 핸들러를 등록해서 내부에서 색상을 변경하면 된다.
afx_msg void OnCustomDraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
{
*pResult = CDRF_DODEFAULT;
POSITION pos = GetFirstSelectedItemPosition();
int nSel = GetNextSelectedItem(pos);
int row = (int)lplvcd->nmcd.dwItemSpec;
if( row == nSel )
{
lplvcd->clrText = GetSysColor(COLOR_HIGHLIGHTTEXT);
lplvcd->clrTextBk = GetSysColor(COLOR_HIGHLIGHT);
}
else
{
lplvcd->clrText = RGB(0,0,0);
lplvcd->clrTextBk = RGB(255,255,255);
}
}
break;
default:
*pResult = CDRF_DODEFAULT;
break;
}
}
단, tree 스타일에 LVS_SHOWSELALWAYS 속성이 있으면 안된다.
(control property -> Always show selection = false)