Solved

Not drawing the focus rectangle in CTreeCtrl

Posted on 2000-04-27
7
832 Views
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?
0
Comment
Question by:Hat32
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:yarond
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...
0
 

Author Comment

by:Hat32
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.
0
 
LVL 1

Expert Comment

by:yarond
ID: 2765861
In SetItemState, for the nState parameter, try putting 0.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:Hat32
ID: 2765883
I get the same result.
0
 
LVL 1

Expert Comment

by:yarond
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?
0
 
LVL 1

Accepted Solution

by:
yarond earned 50 total points
ID: 2765983
Or instead of changing the state you can do:
m_WillowTree.SelectItem(NULL);
But then you'll have to keep track of the selection and keyboard input yourself.
0
 

Author Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now