改变CListView中的ListCtrl颜色

本文转自:http://hi.baidu.com/mingyuejingque/blog/item/c62b99035b47728dd43f7cba.html/cmtid/f608d18fc9207ae0f11f363d

 

 

在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;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值