CTreeCtrl突出显示项目的一部分 [英] CTreeCtrl highlight part of a item

查看:74
本文介绍了CTreeCtrl突出显示项目的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时制作了一个CTreeCtrl,当我点击一个按钮时,我想要只从一个项目中选择一个部分。有没有办法做到这一点?

解决方案

如果你想检测一个比一个项目更精细的谷物点击并只绘制一个项目的一部分,那么你''需要覆盖TreeControl的选择和绘画。

您需要查找所谓的 CustomDraw 的详细信息,如果这还不够,您可能不得不诉诸 OwnerDraw 虽然我不认为我曾经见过一个完全的OwnerDraw Tree Control,但这是一项艰苦的工作。



对于部分项目点击检测你''我需要挂钩基于普通项目的点击检测,然后获取鼠标在发送消息时所处的确切位置,虽然我不能立即记住你是如何获得它的。

那么你可能需要自己进行子项目计算,可能是根据自定义项目绘制时缓存的信息。

您还需要存储一组选择状态,每个子项可能会有1位,与您的其他项数据一起,以便您知道是否将每个子项绘制为选定或未选中当你收到油漆请求时。



你肯定需要一堆示例代码才能在适当的位置获得自定义绘制树控件的所有正确的东西但我确定有一些有用的CP文章,如这一篇 [< a href =http://www.codeproject.com/Articles/325/A-custom-drawn-TreeList-Controltarget =_ blanktitle =新窗口> ^ ]让你入门

I made a CTreeCtrl on runtime and I want, when i click a button, to select only a part from an item. Is any way to do this?

解决方案

If you want to detect a click at a finer grain than a single item and paint only part of an item as selected then you''re going to need to override both selection and painting for the TreeControl.
You''ll need to look up the details of what is called CustomDraw and if that is not enough you may have to resort to OwnerDraw although I don''t think I''ve ever seen a fully OwnerDraw Tree Control, that is a lot of hard work.

For the partial item click detection you''ll need to hook into the ordinary item based click detection, then get the exact position the mouse was at when the message was sent which is available although I can''t immediately remember how you get it.
Then you''ll need to do the sub item calculation yourself probably based on information cached when you did the custom item painting.
You''ll also need to store a set of selection states, 1 bit per sub item will probably do, alongside your other item data so that you know whether to paint each sub item as selected or unselected when you get a paint request.

You''ll definitely need a pile of sample code to get all the right things in the right places for a Custom Draw Tree Control but I''m sure there are helpful CP articles like this one [^]to get you started.


这篇关于CTreeCtrl突出显示项目的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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