ListCtrl控件着色
最近在写一款山寨的反病毒软件,大致功能已经实现,还有一些细小的环节需要细化。
其中,在界面编程中,就用到了给ListCtrl控件着色,查看了网上一些文章,终于实现了。
其实说白了,原理很简单,就是ListCtrl在插入一个Item的时候,会发送一个NM_CUSTOMDRAW的消息,我们只要实现这个消息响应函数,并在里面绘制我们的颜色就可以了。
但是响应这个消息在VC6.0下需要自己实现:
1.在头文件中声明函数:afx_msg void OnCustomdrawMyList( NMHDR* pNMHDR, LRESULT* pResult );
2.在cpp文件中添加消息映射:ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST, OnCustomdrawMyList)
3.函数的实现:
void CXXX::OnCustomdrawMyList( NMHDR* pNMHDR, LRESULT* pResult )
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
// Take the default processing unless we set this to something else below.
*pResult = 0;
// 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;
}
// 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_clrText;
int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
// 根据文本内容判断使ListCtrl不同颜色现实的条件
CString str = m_list.GetItemText(nItem ,0);
if (str == "0")
{
m_clrText = RGB(12,26,234);
}
else if (str == "1")
{
m_clrText = RGB(0,0,0);
}
else
{
m_clrText = RGB(255, 0, 0);
}
pLVCD->clrText = m_clrText;
*pResult = CDRF_DODEFAULT;
}
}
最新文章
- Android技术分享收集
- SharePoint 2013 User Profile Services之跨场发布
- jQuery document window load ready 区别详解
- chem02-- ajax登录
- HDU 3336 - Count the string(KMP+递推)
- ANDROID模拟器访问本地WEB应用
- Oracle日常维护脚本
- HASH暴力破解工具-Hashcat
- OLEDB和ODBC的区别(优缺点)
- objective-c内存管理中autorelease的作用
- Letter of inquiry about employment possibilities, e-mail version
- iOS开发笔记:编译时出现的错误和解决办法
- HDU1159-Common Subsequence
- JCL学习
- js导出execl兼容ie Chrome Firefox各种主流浏览器(js export execl)
- Zend Studio 无法打开的解决办法
- Python集合set
- SpringBoot的自动配置
- C#软件监控外部程序运行状态
- Podfile
热门文章
- bad interpreter: No such file or directory解决
- leetcode第一刷_Binary Tree Inorder Traversal
- RadioButton控件
- jsp生命周期和工作原理
- JVM调优总结(四)-垃圾回收面临的问题
- httplib,urllib和urllib2
- android事件传递机制以及onInterceptTouchEvent()和onTouchEvent()详解二之小秘与领导的故事
- UVA 10317 - Equating Equations (背包)
- C#多线程的死锁演示
- 如何捕获Wince下form程序的全局异常