Link to home
Start Free TrialLog in
Avatar of asselins
asselins

asked on

Tooltips for custom tree controls

I'm trying to add tooltip support for this CTreeCtrl derived class I'm working on.  I'm testing the control in a dialog by SubclassDlgItem() it.

The problem I have is I want the tree control to do it's own tooltip handling.  I use CToolTipCtrl, but I also tried overloading some CWnd members.  Right now, no matter what I try, the TTN_NEEDTEXT notifications (I use LPSTR_TEXTCALLBACK) always goes to the parent of the tree control, the dialog.  I want this control to be fully self contained so I don't want to have to add message relaying code to forward the messages from the dialog to the tree.

I tried adding ON_NOTIFY_REFLECT/ON_NOTIFY handlers to the tree, changing the hwnd member of the TOOLINFO struct associated w/ the tooltip to point to the tree, all without success.  The tree never gets called.

So I would like to know what I need to do to solve this.  I'd appreciate all the necessary steps, or better even, a source code example of a CTreeCtrl control that handles it's own tooltips.  That would rock.  Thanks!
Avatar of asselins
asselins

ASKER

I solved it by using the generic CWnd support for tooltips.  You call EnableTooltips(TRUE) in the tree control, and then you have to handle TTN_GETDISPINFO to get the messages.  Simple as that.

Since the rect for the tooltip is the whole control, it will remain showing as long as the mouse is over the client area.  This is inconvenient, so you can handle mouse move in the tree control and call the tooltip's Pop() method to make it disappear when the mouse moves.

Also, from the TTN_GETDISPINFO handler, you have to use ::GetMessagePos() and then translate that using ::ScreenToClient() to get the coords relative to the tree's client area.  Then from that you can do standard hittesting to figure out what item was clicked and so on.
ASKER CERTIFIED SOLUTION
Avatar of Moondancer
Moondancer

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