본문 바로가기

Windows/MFC

CustomDraw ListView

[code]void CListView::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
CListCtrl* listCtrl = GetListCtrl();
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
    
// Take the default processing unless we set this to something else below.
*pResult = CDRF_DODEFAULT;
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
     *pResult = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
    int    nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec ); // 각 라인 설정....
// 글자색 바꾸기..
    COLORREF crTextColor, crBkColor;
if(listCtrl.GetItemText(nItem,0) == "aa") // 첫라인 첫째 글자가 aa 일경우 해당
                                            // 라인색상 변경
{
     crTextColor = RGB(200,200,200);        // 해당 라인의 글자 색 설정..
     crBkColor = RGB(238, 245, 222);        // 해당 라인의 배경 색 설정..
}
else
{
     crTextColor = RGB(0,0,0);        // 해당 라인의 글자 색 설정..
     crBkColor = RGB(238, 236, 222);        // 해당 라인의 배경 색 설정..
}
        
        // Store the color back in the NMLVCUSTOMDRAW struct.
pLVCD->clrText = crTextColor;        // 해당 라인의 글자 색 변경..
pLVCD->clrTextBk = crBkColor;        // 해당 라인의 배경 색 변경..
    
// Tell Windows to paint the control itself.
*pResult = CDRF_DODEFAULT;
}
}

[/code]