listctrl 列的颜色

来源:互联网 发布:淘宝上怎么发布信息 编辑:程序博客网 时间:2024/04/24 00:01

void SSS::OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult )
{
   NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  *pResult = CDRF_DODEFAULT;

    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
    {
        *pResult = CDRF_NOTIFYITEMDRAW;
 }
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
 {
        *pResult = CDRF_NOTIFYSUBITEMDRAW;
 }
    else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
        {
           COLORREF crText, crBkgnd;
       
        if (  nItem == pLVCD->iSubItem )
            {
            crText = RGB(255,0,0);
            crBkgnd = RGB(128,128,255);
            }
       
        else
            {
            crText = RGB(0,0,255);
            crBkgnd = RGB(228,228,228);
           }
 
        // Store the colors back in the NMLVCUSTOMDRAW struct.
        pLVCD->clrText = crText;
        pLVCD->clrTextBk = crBkgnd;
 
        // Tell Windows to paint the control itself.
        *pResult = CDRF_DODEFAULT;
        }

}
 afx_msg void OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult );

ON_NOTIFY ( NM_CUSTOMDRAW, IDC_LIST1, OnCustomdrawMyList )

 

原创粉丝点击