We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Hiding tooltip

roar asked
Medium Priority
Last Modified: 2013-11-19
I'm showing a tooltip like window when the user moves the cursor over the client area. The tooltip is my own CWnd derived class, because I need to display multiline information.
I want the window to disappear when the cursor moves outside the client area. I tried using SetCapture, but I don't get any WM_MOUSEMOVE messages when the cursor moves outside the client area.
The toolbar manages to hide it's tooltip when the cursor moves outside the toolbar, so it should be possible I guess. If you've got some pointers on how to solve this, it would be great.
Watch Question

You must handle WM_NCHITTEST message in all your windows. It's sent to a window when the cursor moves, or when a mouse button is pressed or released. So if this message sent to parent window you must hide tooltip.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Isn't there some other way to do this? I have many windows, some of them are third party libraries. It's going to be kind of messy to insert code to handle this in all of them. Besides, all the other windows don't have to explicitly notify the toolbar that the cursor has moved outside the the toolbar. How does the toolbar know that the cursor has moved?

There is also one way to hide tooltips: handle TTN_POP message (I hope you use TTN_NEEDTEXT message to show tooltips). But there is little problem: window receive TTN_POP message before mouse cursor leave window's area. See for example how tooltip hides inside VC.


I don't use TTN_NEEDTEXT , I just show it in OnMouseMove. Is it better to use TTN_NEEDTEXT ?
You mentioned WM_NCHITTEST , will it work to make the window that displays the tooltips capture the mouse and handle WM_NCHITTEST ? Then check in the WM_NCHITTEST handler if cursor moves outside the window, and hide tooltip if it does?

Any window receive WM_NCHITTEST when mouse cursor is inside window area. When cursor leave window area another window receive this message. So all your windows must handle this message to show and hide tooltip (include buttons, statics etc). This way is very laborious.
I propose another way. You must use EnableToolTips() method for your View class (after creating) and handle TTN_NEEDTEXT message to show tooltip and TTN_POP to hide it.


I found a sample at
that shows how to use the tooltips in a view as you describe. The problem is that I need to display multiple line of information. The default tooltip window will not do that, so I need to use my own class instead. I am able to display both the single line tooltip and my own multiline tooltip simultaneously, but that is obviously not what I want.
If I don't give the tooltip any text in the TTN_NEEDTEXT handler, only my multiline tooltip window shows, but then I don't get the TTN_POP notification either. And then I'm back to the original problem with removing the tooltip. Is it possible to derive a class from CToolTipCtrl, and make MFC call that to display tooltips? How do I do that?

So I see only 1 very laborious way: using WM_NCHITTEST message handling for all windows. You may reject my answer. May be anybody can say more (but I doubt that no).
Good luck.


Alright, thank you for fast and informative answers. It would be interesting to see a comment from Mike Blaszczak on this issue, could you pass it on to him please? (Is it possible to solve this by subclassing or by using undocumented MFC?)

I can't pass question to anybody. To do this you must reject my answer. This is only way for your question to restore status to "Questions Awaiting Answers".
Moreover I don't know who is Mike Blaszczak. Sorry.

You're right.  Subclass your client window and handle the WM_NCHITTEST for THAT window and ONLY that window.


When you say client window, do you mean the tooltip window or the view? What should the WM_NCHITTEST handler look like?



Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.