Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 859
  • Last Modified:

Not drawing the focus rectangle in CTreeCtrl

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
Hat32
Asked:
Hat32
  • 4
  • 3
1 Solution
 
yarondCommented:
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
 
Hat32Author Commented:
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
 
yarondCommented:
In SetItemState, for the nState parameter, try putting 0.
0
Technology Partners: 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!

 
Hat32Author Commented:
I get the same result.
0
 
yarondCommented:
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
 
yarondCommented:
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
 
Hat32Author Commented:
That removed the focus and selection.  I will try this approach, keeping track of the selection and keyboard input myself.  Thanks.
0

Featured Post

Technology Partners: 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!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now