本文共 954 字,大约阅读时间需要 3 分钟。
添加ListCtrl的CustomDraw事件。
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
// Take the default processing unless we set this to something else below. *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 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); // 字体颜色 clrNewBkColor = RGB(255,255,0); // 背景色 } else { clrNewTextColor = RGB(0,0,0); clrNewBkColor = RGB(255,255,255); } pLVCD->clrText = clrNewTextColor; pLVCD->clrTextBk = clrNewBkColor; // Tell Windows to paint the control itself. *pResult = CDRF_DODEFAULT; }转载地址:http://ewfcb.baihongyu.com/