呵呵,没有及时回看你的帖子,不知道现在你的问题解决了没有。在派生类例如CListCtrlEx中重载OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult),并添加消息映射 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw) 响应NM_CUSTOMDRAW消息。 void CListCtrlEx::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); bool bDBImplFail = false ; CString str1 = GetItemText(nItem ,1); if (str1 == "love") //这里的条件自己写就可以了。 { 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); } if ( nItem == GetSelectionMark() ) //这里的条件自己写就可以了。 { m_crTextBk = RGB( 49, 106, 197 ); m_clrText = RGB( 255, 1, 1 ); } pLVCD->clrTextBk = m_crTextBk; pLVCD->clrText = m_clrText;
应该是SetSelectionMark(nIndex),但是这个函数是设置某个当前为选中状态,不能把它变灰啊?
自己写个派生类 CListCtrl
重载OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
响应NM_CUSTOMDRAW消息。
void CListCtrlEx::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);
bool bDBImplFail = false ; CString str1 = GetItemText(nItem ,1); if (str1 == "love") //这里的条件自己写就可以了。
{
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);
}
if ( nItem == GetSelectionMark() ) //这里的条件自己写就可以了。
{
m_crTextBk = RGB( 49, 106, 197 );
m_clrText = RGB( 255, 1, 1 );
}
pLVCD->clrTextBk = m_crTextBk;
pLVCD->clrText = m_clrText;
*pResult = CDRF_DODEFAULT;
}
}