-
Reflect TTN_NEEDTEXT ???
This one drives me crazy, so I first have to calm down a little.. This post contains much text and no code by now, sorry!
I'm developing an owner-drawn CListCtrl that subclasses an owner-drawn CHeaderCtrl. By now, I've added (besides a lot of drawing stuff) some tooltips to both the header control and the list control. Let's say that there are "not so many" problems doing this by using the ToolTip integrated in the CWnd - besides:
a) sending a message to the tooltip (e.g. for setting the maxwidth) is hard enough - virtually impossible without peeking into MFC proprietary and undocumented code (how do we get the tooltip of the window object?).
b) the tooltip control isn't created when PreSubclassWindow of the HeaderCtrl is hit, so there seems to be no easy way to do some default settings (like maxwidth). a workaround would be to set it every time TTN_NEEDTEXT arrives :(
c) the header control and the list control share one tooltip. no way to set the header tooltip - let's say - to a different background color or whatever. Same workaround possible as in (b) :(
While I found a solution that more or less works by now, I'm quite unhappy and considered embeding a CToolTipCtrl member variable in the CHeaderCtrl. Since the item positions must be calculated "live", I'd like to add the header control itself by "AddTool(this,LPSTR_TEXTCALLBACK)" and use message reflection (ON_NOTIFY_REFLECT macro) to handle the TTN_NEEDTEXT message in the header control instead of the parent of "this".
What a bummer! The reflection does not work: The TTN_NEEDTEXT is passed to the parent window (the list control) instead. Everything works fine when I add a ReflectLastMsg(Header.GetSafeHwnd(),pResult) to the notification handler of the list control - but that's not my idea of control/code independence!
Question:
Is there a way to incorporate individual and independent ToolTip controls into my header and list control class where both the header and list control class handle the TTN_NEEDTEXT notification
messages on their own?
Thank you for any suggestion(s) (and for reading this)
Oliver.
-
Run in the same problem
Hi Oliver,
your message is more than a year old. I hope you solved the problem.
If so, can you drop me a note how you solved it?
Thanks in advance.
Frank Kobs
-
Hi Frank
You're right, it's long ago. I just peeked into my old code and here's what I can tell from a first glance:
- I added an own CToolTipCtrl member variable.
- I handled TTN_NEEDTEXT like this (can't remember why I needed to handle TTN_NEEDTEXTW and why I setup the range 0,0xffff???)
ON_NOTIFY_EX_RANGE (TTN_NEEDTEXTW , 0, 0xffff, OnToolTipNotify)
- I called EnableToolTips(FALSE) in PreSubclassWindow and added the whole client area as a tooltip.
Code:
// disable window object tooltips
EnableToolTips(FALSE);
// add the whole client rect to the member tooltip control
{
CRect rcClient(0,0,0,0);
GetClientRect(rcClient);
ToolTips.AddTool(this,LPSTR_TEXTCALLBACK,&rcClient,1);
ToolTips.EnableToolTips(TRUE);
}
- in OnToolTipNotify, I get the mouse position in client coords and use a little function to get the "Item from point". Then I set the pointer (TOOLTIPTEXTA*)pNMHDR->lpszText to a buffer which holds the tooltip, set pResult=NULL and return FALSE (important!).
Btw. I allocated a buffer for the tooltip and always remember the rectangle of the last hovered column so that I don't have to re-search the item on every mouse movement.
Hope this helps
Oliver