具有项边框的CTreeCtrl [英] CTreeCtrl with Item Border

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

问题描述

大家好,



我现在花了一段时间寻找解决问题的方法 - 没有成功。所以我希望有人可以帮助我。这是问题所在:



我有一个来自CTreeCtrl的派生类。当我在TreeCtrl中选择一个项目时,它会以蓝色突出显示,并带有一个小的红色/黑色点边框。



当我的TreeCtrl失去焦点时,所选项目之前获得灰色,带有这个小边框。我目前能够将灰色设置为任何其他颜色或操纵文本颜色/字体。但是我无法得到这个小边框 - 我想要。



那么,你们之前是否有人遇到过这个问题并能够帮助我? br />
谢谢。

解决方案

看起来你需要使用Owner Draw功能。例如,请参阅此CodeProject文章: VividTree - 丰富多彩的风景如画的所有者绘制的CTreeCtrl类 [ ^ ]。



-SA


感谢VividTree的链接。

但同时我找到了我想要的东西。



我扩展了我的customdraw方法我的TreeCtrl与ITEMPOSTPAINT绘图阶段在TreeCtrl没有焦点的情况下绘制我想要另外突出显示的项目边框:



  case  CDDS_ITEMPOSTPAINT:
if ((tvcdPtr-> nmcd.uItemState& CDIS_SELECTED )
&&(GetFocus()!= ))
{
RECT r;
// Rect的边界
CreatePen(PS_SOLID, 1 ,RGB( 0 0 0 ));
// 填充Rect - 此处透明
SelectObject(tvcdPtr-> nmcd.hdc,GetStockObject(HOLLOW_BRUSH));

HTREEITEM hItem = GetSelectedItem();
GetItemRect(hItem,& r,TRUE);
矩形(tvcdPtr-> nmcd.hdc,r.left,r.top,r.right,r.bottom);

// 替代
// DrawFocusRect(tvcdPtr-> nmcd.hdc,& r);
}
断裂;


Hi everyone,

I spent now a while looking for a fix of my problem - w/o success. So I hope someone of you can help me. Here's the problem:

I do have a derived class from CTreeCtrl. When I select an item within my TreeCtrl it gets highlighted in blue with a small border of red/black dots.

When my TreeCtrl lost the focus the before selected item gets colored in grey w/o this small border. I am currently able to set the grey color to any other color or manipulate the text color/font. But I am not able to get this small border - and I want to.

So, does anyone of you faced this problem before and is able to help me?
Thanks.

解决方案

It looks like you need to use the "Owner Draw" feature. See, for example, this CodeProject article: VividTree - A Colorful and Picturesque Owner Drawn CTreeCtrl Class[^].

—SA


Thanks for the link to the VividTree.
But in the meanwhile I found what I was looking for.

I extended my customdraw method of my TreeCtrl with the ITEMPOSTPAINT drawing stage to draw the border around the items I want to additionally highlight when the TreeCtrl does not have the focus:

case CDDS_ITEMPOSTPAINT:
	if((tvcdPtr->nmcd.uItemState & CDIS_SELECTED)
	&& (GetFocus() != this))
	{
		RECT r;
		//Border of Rect
                CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); 
                //Fill of Rect - here transparent
		SelectObject(tvcdPtr->nmcd.hdc, GetStockObject(HOLLOW_BRUSH)); 

        	HTREEITEM hItem = GetSelectedItem();
		GetItemRect(hItem, &r, TRUE);
		Rectangle(tvcdPtr->nmcd.hdc, r.left, r.top, r.right, r.bottom);

                //Alternative
		//DrawFocusRect(tvcdPtr->nmcd.hdc, &r);
	}
	break;


这篇关于具有项边框的CTreeCtrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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