Not drawing the focus rectangle in CTreeCtrl

Posted on 2000-04-27
Last Modified: 2008-03-10
I have a CTreeCtrl and I would like to prevent it from drawing the focus rectangle around an item after that item is selected.  I have tried responding to the NM_CUSTOMDRAW notification, but it seems that if I want to do anything but change the text color, I have to draw the entire item.  Is there an alternative?
Question by:Hat32
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 2765376
What happens if you track the selections yourself instead of letting the control do it?
after every TVN_SELCHANGED is sent, just unselect the item (so no focus rectangle will be drawn) but keep tracking of what the item was. Then whenever the selection is changed because of a keystroke just set the selection to the appropriate item manually...

Author Comment

ID: 2765808
After the TVN_SELCHANGED is sent, I unselected the item with the statement
m_WillowTree.SetItemState( pNMTreeView->itemNew.hItem, ~TVIS_SELECTED, TVIS_SELECTED );
but the focus rectangle is still drawn.

Expert Comment

ID: 2765861
In SetItemState, for the nState parameter, try putting 0.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 2765883
I get the same result.

Expert Comment

ID: 2765935
Hmmm... Looks as if the rect is drawn if the tree control has the focus, even if it's told not to show the selected text.
For some reason when I try to run a test program in debug mode usually it doesn't happen, so I didn't notice at first...

One way I found around this is to set the TVS_FULLROWSELECT style, since in this mode it only paints the rect in the selection color and doesn't draw the rect's frame, and so this code really clears it. This can't work if you're using lines, though. Are you?

Accepted Solution

yarond earned 50 total points
ID: 2765983
Or instead of changing the state you can do:
But then you'll have to keep track of the selection and keyboard input yourself.

Author Comment

ID: 2766019
That removed the focus and selection.  I will try this approach, keeping track of the selection and keyboard input myself.  Thanks.

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question