天天看点

listctrl 列的颜色

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 )