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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值