I've created a basic MFC application that contains the following classes:
* ToolTipDemoApp (derived from CWinApp)
* ToolTipDemoFrame (derived from CWndFrame)
* Canvas (Derived from CWnd)
This application is a test application so I can better understand the confusing mess that are tooltips in MFC. All I want it to do is display a tooltip when the mouse hovers over the Canvas.
The problem I have is that OnToolHitTest in the Canvas class is never called. I've enabled tooltips in Canvas::OnCreate. I also have a handler for TTN_NEEDTEXT, but since the hit test function is never called it hasn't got that far yet (not that the MSDN documentation says I need the OnToolHitTest function anyway).
I've managed to get the tooltip working 95%. The initial problem was that I had an incorrect function signiature for OnToolHitTest. It should be:
virtual int OnToolHitTest ( CPoint point, TOOLINFO* pTI ) const;
Now I'm at the point where I have tracking tooltips that show the cursor location. The tooltip updates correctly, and is even multiline, but once the mouse leaves the CWnd derived class (Canvas), the tooltip never reappears when the cursor goes back in again.
I think this has something to do with the return value of OnToolHitTest, but I can't figure it out. MSDN is rubbish at explaining what needs to be done.
There are a few differences with the code in that link:
1. The control intended as the target for the tooltip is derived from CDialog, whereas I am deriving from CWnd (perhaps this isn't a massive difference)
2. The tooltip is implemented using CToolTipCtrl. Perhaps I do need to use this in order to get the behaviour I want, but nothing suggests that so far and I would prefer to avoid it for the time being.
I am able to test when the mouse leaves the CWnd client area; however, I'm doing this using SetCapture and ReleaseCapture, which seems like a stupid way of doing it.