我最近做的程序需要改变listctrl中某列的全部颜色,例如有11行,5列.我需要这11行中第2列全部改为别的颜色,代码如下(看别人的例子学的),
这个人添加了一个OnCustomdrawMyList函数,具体内容如下:void CHighlightListCtrlDlg::OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult )
{
//This code based on Michael Dunn's excellent article on
//list control custom draw at http://www.codeproject.com/listctrl/lvcustomdraw.asp NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );    // Take the default processing unless we set this to something else below.
    *pResult = CDRF_DODEFAULT;    // 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 notification message for an item.  We'll request
        // notifications before each subitem's prepaint stage.

        *pResult = CDRF_NOTIFYSUBITEMDRAW;
}
    else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
{

COLORREF clrNewTextColor, clrNewBkColor;
        
int    nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec ); CString strTemp = m_ctListCtrl.GetItemText(nItem,pLVCD->iSubItem); if(strTemp == m_strName)
{
clrNewTextColor = RGB(255,0,0); //Set the text to red
clrNewBkColor = RGB(255,255,0); //Set the bkgrnd color to blue
}
else
{

clrNewTextColor = RGB(0,0,0); //Leave the text black
clrNewBkColor = RGB(255,255,255); //leave the bkgrnd color white
} pLVCD->clrText = clrNewTextColor;
pLVCD->clrTextBk = clrNewBkColor;

        
        // Tell Windows to paint the control itself.
        *pResult = CDRF_DODEFAULT;
        
        
}
}
其中:
if(strTemp == m_strName)
{
clrNewTextColor = RGB(255,0,0); //Set the text to red
clrNewBkColor = RGB(255,255,0); //Set the bkgrnd color to blue
}
就是改变颜色的部分,如果m_strName等于listctrl中的任意一个值,那么该值的颜色就为红色.
现在的问题是我listctrl控件里第2列的值没3秒变一次,而且数值是随机的,我想把整列(第2列)的颜色全部改为红色,请问上面的程序如何修改? 上面的只是当m_strName等于listctrl里面任意一项的值的时候才改变的.请问如何改变特定的列的颜色啊???随机的就不知道值了就不能用上面的方法了,小弟不解,请给为老师给予指点!!!!!!!!谢谢!!!!!!!!!!!