Link to home
Start Free TrialLog in
Avatar of Hat32
Hat32

asked on

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?
Avatar of yarond
yarond

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...
Avatar of Hat32

ASKER

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.
In SetItemState, for the nState parameter, try putting 0.
Avatar of Hat32

ASKER

I get the same result.
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?
ASKER CERTIFIED SOLUTION
Avatar of yarond
yarond

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hat32

ASKER

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