在CSDN上瞧到一个好东东~~~~~~哈哈可能有用的,就抓来这里了。
通过处理NM_CUSTOMDRAW,可以实现你的功能!但是NM_CUSTOMDRAW在Class Wizard中有可能看不到,不用管他,直接按照小面的方法添加处理过程即可!
1. 在消息映射表中
BEGIN_MESSAGE_MAP(CIHISSERVERView, CListView)
//{{AFX_MSG_MAP(CIHISSERVERView)
...
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
...
//}}AFX_MSG_MAP
// Standard printing commands
END_MESSAGE_MAP()
2.在头文件中
afx_msg void OnCustomDraw(NMHDR*, LRESULT*);
3.在cpp文件中
void CIHISSERVERView::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
// Contains information specific to an NM_CUSTOMDRAW
// notification message sent by a list-view control.
// mean:draw each item.set txt color,bkcolor....
NMLVCUSTOMDRAW* pLVCD = (NMLVCUSTOMDRAW*)(pNMHDR);
// Take the default processing unless we set this to something else below.
*pResult = CDRF_NEWFONT;
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if ( pLVCD->nmcd.dwDrawStage==CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
// This is the notification message for an item. We'll request
// notifications before each subitem's prepaint stage.
else if ( pLVCD->nmcd.dwDrawStage==CDDS_ITEMPREPAINT )
{
COLORREF m_crTextBk , m_clrText;
int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
// 判断使ListCtrl不同颜色现实的条件
CListCtrl &m_list = GetListCtrl();
CString str1 = m_list.GetItemText(nItem ,15);
bool bDBImplFail = false ;
if (str1 == "信息不祥")
{
m_crTextBk = RGB(255, 255, 0) ;
m_clrText = RGB(128, 0, 128) ;
}
else
{
m_crTextBk = RGB(150, 255, 255);
m_clrText = RGB(12,26,234);
}
pLVCD->clrTextBk = m_crTextBk;
pLVCD->clrText = m_clrText;
*pResult = CDRF_DODEFAULT;
}
}