Solved

Hiding tooltip

Posted on 1997-05-26
12
618 Views
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.
0
Comment
Question by:roar
  • 6
  • 5
12 Comments
 
LVL 4

Accepted Solution

by:
AVaulin earned 70 total points
ID: 1301805
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.
0
 

Author Comment

by:roar
ID: 1301806
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?
0
 
LVL 4

Expert Comment

by:AVaulin
ID: 1301807
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.
0
 

Author Comment

by:roar
ID: 1301808
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?

0
 
LVL 4

Expert Comment

by:AVaulin
ID: 1301809
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.
0
 

Author Comment

by:roar
ID: 1301810
I found a sample at
http://ourworld.compuserve.com/homepages/mrconway/tooltip.htm
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?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 4

Expert Comment

by:AVaulin
ID: 1301811
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.
0
 

Author Comment

by:roar
ID: 1301812
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?)
0
 
LVL 4

Expert Comment

by:AVaulin
ID: 1301813
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.
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1301814
You're right.  Subclass your client window and handle the WM_NCHITTEST for THAT window and ONLY that window.
0
 

Author Comment

by:roar
ID: 1301815
When you say client window, do you mean the tooltip window or the view? What should the WM_NCHITTEST handler look like?

0
 

Author Comment

by:roar
ID: 1301816


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now