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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

739 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