Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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
 
Share this answer
 
Comments
CPallini 20-Nov-13 13:27pm    
5.
Sergey Alexandrovich Kryukov 20-Nov-13 13:28pm    
Thank you, Carlo.
—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:

C++
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;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900