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;
    }
}

 

posted @ 2013-01-24 09:10  瓜蛋  阅读(771)  评论(0编辑  收藏  举报