-
December 6th, 2008, 05:08 AM
#1
Tooltips on CWnd Derived Class
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).
The code (for the next month) can be found at: www.pastebin.com/m63942e7a
-
December 6th, 2008, 02:21 PM
#2
Re: Tooltips on CWnd Derived Class
What is this Canvas supposed to be? And what's the story of that link?
-
December 7th, 2008, 01:50 AM
#3
Re: Tooltips on CWnd Derived Class
Originally Posted by rioch
The link points to an invalid post.
Regards,
John,
http://www.simpletools.co.in
-
December 7th, 2008, 10:26 AM
#4
Re: Tooltips on CWnd Derived Class
The canvas does nothing special. It will have some things painted onto it in the OnPaint function, but it is totally unrelated to the tooltip.
Sorry about the link. It shouldn't have the www. at the front. Try this one now: pastebin.com/m63942e7a
What I intend to do is show the cursor location in a tracking tooltip when in the canvas. At the moment, a basic tooltip nor a tracking tooltip cause the onhittest function to be called.
-
December 8th, 2008, 05:40 AM
#5
Re: Tooltips on CWnd Derived Class
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.
-
December 8th, 2008, 06:35 AM
#6
Re: Tooltips on CWnd Derived Class
-
December 8th, 2008, 07:10 AM
#7
Re: Tooltips on CWnd Derived Class
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|