CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2008
    Posts
    29

    Question 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

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Tooltips on CWnd Derived Class

    What is this Canvas supposed to be? And what's the story of that link?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Nov 2008
    Posts
    13

    Re: Tooltips on CWnd Derived Class

    Quote Originally Posted by rioch View Post
    The code (for the next month) can be found at: www.pastebin.com/m63942e7a
    The link points to an invalid post.

    Regards,
    John,
    http://www.simpletools.co.in

  4. #4
    Join Date
    Dec 2008
    Posts
    29

    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.

  5. #5
    Join Date
    Dec 2008
    Posts
    29

    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.

  6. #6
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

  7. #7
    Join Date
    Dec 2008
    Posts
    29

    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
  •  





Click Here to Expand Forum to Full Width

Featured