在运行时更改文本颜色listctrl [英] Changing text color listctrl at run time

查看:73
本文介绍了在运行时更改文本颜色listctrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友
我只想在listctrl的一行中更改文本的颜色.我的程序必须在OnTimer过程中执行.
因此,我创建了从CListCtrl驱动的CMoja1ListCtrl类,并实现了NM_CUSTOMDRAW消息处理程序. 本文中类似的所有内容:http://msdn.microsoft.com/zh-cn/library/ms364048(VS.80).aspx
现在如何传递给我要更改的OnNMCustomdraw行数? SendMessage(NM_CUSTOMDRAW,0,linenumber)?
有什么建议吗?
如果有人帮助我解决此问题,我将非常感激.

Hello Friends
I want to change the color of text in only one row in listctrl. My program I must do it in OnTimer procedure.
So I created class CMoja1ListCtrl drived from CListCtrl and implemented an NM_CUSTOMDRAW message handler.
Everything like in this article : http://msdn.microsoft.com/en-us/library/ms364048(VS.80).aspx
Now how to pass to OnNMCustomdraw number of row I want to change ? SendMessage(NM_CUSTOMDRAW,0,linenumber) ?
Any suggestions?
I would be very grateful if someone help me with this problem.

推荐答案

要注意的重要一点是,您自己不会触发NM_CUSTOMDRAW事件.您只处理在适当的时间由基础代码触发的事件以进行绘制.
因此,如果要在特定时间更改项目颜色,则必须使列表控件无效以强制重绘(导致触发NM_CUSTOMDRAW事件),并让处理程序根据需要更改颜色.
在您的情况下,我想您的计时器处理程序将执行无效操作,并且可能会设置您的自定义绘图处理程序可以使用的颜色.
The important thing to note is that you do not fire the NM_CUSTOMDRAW event yourself. You only handle the event which is fired by the underlying code at the appropriate time for drawing.
So, if you want to change an item colour at a particular time, you must invalidate the list control to force a redraw (causing the NM_CUSTOMDRAW event to fire) and let your handler change the colour as required.
In your case I guess your timer handler will do the invalidation and perhaps set up a colour which your custom draw handler can use.


您是否看到了
Did you see this[^] page at MSDN?

When your code is called, (via a NM_CUSTOMDRAW message) you can determine that the handler has been called for a listview or a tree-view then treat the data pointed to by lParam in the appropriate way .

In the case of a listview, the data is a NMLVCUSTOMDRAW struct, the first member of which NMCUSTOMDRAW struct. Inside this NMCUSTOMDRAW struct is a member called dwItemSpec. This contains your item number.


这篇关于在运行时更改文本颜色listctrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆