CListCtrl 改变某行颜色

void CJx3LoginDlg::OnCustomdrawList( NMHDR* pNMHDR, LRESULT* pResult )
{
    NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );

    // Take the default processing unless we set this to something else below.
    *pResult = 0;

    // First thing - check the draw stage. If it's the control's prepaint
    // stage, then tell Windows we want messages for every item.
    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
    {
        *pResult = CDRF_NOTIFYITEMDRAW;
    }
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
    {
        // This is the prepaint stage for an item. Here's where we set the
        // item's text color. Our return value will tell Windows to draw the
        // item itself, but it will use the new color we set here.
        // We'll cycle the colors through red, green, and light blue.
        COLORREF crText;
        UINT     nRow;
        nRow=pLVCD->nmcd.dwItemSpec;
        
        BOOL bRed =FALSE;
        CString strTimeEnd = g_userList.GetUserFormUser(m_ListCtrl.GetItemText(nRow,IUSER)).m_TimeRemain;
        if(!strTimeEnd.IsEmpty())
        {
            COleDateTime tm_end;
            tm_end.ParseDateTime(strTimeEnd);
            COleDateTime CurTime = COleDateTime::GetCurrentTime();
            COleDateTimeSpan ret = tm_end - CurTime;
            LONG nRemainDays = ret.GetDays();
            if(nRemainDays <=2  && nRemainDays > -10 )
            {
                bRed = TRUE;
            }
        }
        else
            bRed = FALSE;

        //bRet 为真的话,将该行字体显示为红色,否则显示为黑色
        if(bRed)
            crText = RGB(255,0,0);
        else
            crText = RGB(0,0,0);

        // Store the color back in the NMLVCUSTOMDRAW struct.
        // pLVCD->clrText = crText;
        pLVCD->clrText=crText;
        // Tell Windows to paint the control itself.
        *pResult = CDRF_DODEFAULT;
    }
}
本人新博客网址为:http://www.hizds.com
本博客注有“转”字样的为转载文章,其余为本人原创文章,转载请务必注明出处或保存此段。c++/lua/windows逆向交流群:69148232
原文地址:https://www.cnblogs.com/zhangdongsheng/p/2874197.html