我照网上的代码改变Clistctrl单元格的颜色,用hitsubitem捕捉单元格后,SetItemColor(25,3,RGB(255,0,0));//改变25行3列为红色。
updatadata(true);//我也试过updatadata(false);前几天实现的很好,今天不知什么原因,鼠标点击单元格后,不立即变色,必须有另外一个窗口覆盖该单元格再挪开,颜色才改变。请教大家如何处理。下面是网上的代码:BEGIN_MESSAGE_MAP(CColorListCtrl,   CListCtrl) 
        ON_NOTIFY_REFLECT(NM_CUSTOMDRAW,   OnNMCustomdraw) 
END_MESSAGE_MAP() COLORREF   CColorListCtrl::SetItemColor(int   nRow,   int   nCol,   COLORREF   clrItem) 

        int   nCols   =   GetHeaderCtrl()-> GetItemCount(); 
        int   nRows   =   GetItemCount(); 
        if   (nCol   > =   nCols   ||   nRow   > =   nRows) 
                return   COLORREF(-1);         for   (int   i   =   m_lstItemColor.GetCount();   i   <   nRow   +   1;   i++) 
        { 
                COLORREF   *clrCol   =   new   COLORREF[nCols]; 
                ZeroMemory(clrCol,   sizeof(clrCol)); 
                m_lstItemColor.AddTail(clrCol); 
        }         for   (int   i   =   0;   i   <   nRows;   i++) 
        { 
                if   (i   ==   nRow) 
                { 
                        COLORREF   *clrCol   =   m_lstItemColor.GetAt(m_lstItemColor.FindIndex(nRow)); 
                        COLORREF   clrRet   =   clrCol[nCol]; 
                        clrCol[nCol]   =   clrItem; 
                        return   clrRet; 
                } 
        }         return   COLORREF(-1); 
} void   CColorListCtrl::OnNMCustomdraw(NMHDR   *pNMHDR,   LRESULT   *pResult) 

        LPNMLVCUSTOMDRAW   pNMCD   =   reinterpret_cast <LPNMLVCUSTOMDRAW> (pNMHDR); 
        //   TODO:   在此添加控件通知处理程序代码 
        *pResult   =   0;         int   nRows   =   m_lstItemColor.GetCount(); 
        int   nRow   =   int(pNMCD-> nmcd.dwItemSpec); 
        COLORREF   *clrCol   =   NULL; 
        if   (nRows   &&   nRow   <   nRows) 
        { 
                clrCol   =   m_lstItemColor.GetAt(m_lstItemColor.FindIndex(nRow)); 
        }         switch(pNMCD-> nmcd.dwDrawStage) 
        { 
        case   CDDS_PREPAINT   : 
                *pResult   =   CDRF_NOTIFYITEMDRAW; 
                return;         case   CDDS_ITEMPREPAINT: 
                if   (clrCol) 
                        pNMCD-> clrText   =   clrCol[0]; 
                *pResult   =   CDRF_NOTIFYSUBITEMDRAW; 
                return;         case   CDDS_SUBITEM   |   CDDS_ITEMPREPAINT: 
                if   (clrCol) 
                        pNMCD-> clrText   =   clrCol[pNMCD-> iSubItem]; 
                *pResult   =   CDRF_NEWFONT; 
                return; 
        } }