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;
    }
}
复制代码

 

相关文章
C#-DevExpress改变表格行颜色
DevExpress改变表格行颜色
281 0
|
C#
C#-改变表格行颜色
C#改变表格行颜色
314 0
设置CListCtrl网格线
设置CListCtrl网格线
207 0
改变DBGRID的选中行的颜色
默认DBGRID选中行的颜色为深蓝色,可以在程序中改变 在DBGRID的OnDrawColumnCell中写入 if (State=[gdSelectd..gdFocused,gdCurrent]) then begin    Grid.
890 0
改变ListBoxItem选中的颜色
原文:改变ListBoxItem选中的颜色 改变ListBoxItem主要是改变的style   下面直接看代码吧!!! 1 2 3 4 5 ...
824 0

热门文章

最新文章