Solved

Deciding when a tooltip appears

Posted on 1997-11-08
4
541 Views
Last Modified: 2013-11-20
I have created an ownerdrawn button and would like to be
able to specify that a tooltip will appear only when the
cursor is within a specific region in the button. I managed
to control when the tooltip shows by overriding WM_NCHITTEST
but I don't know how to force the tip to pop, when the mouse
exits the region (I tried overriding WM_TOOLHITTEST in the
parent container -CView derived- to no avail). Any pointers?
0
Comment
Question by:alpar
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
kburns102197 earned 50 total points
ID: 1309596
Did you first overide CToolTipCtrl and add member functions that take advange of the fact that a tooltip control can do its own subclassing?
A tooltip control has to be able to see the mouse messages a tool receives so it know when to display the tooltip.  This works great if your pointer to the window (eg pWnd) points to top level window or a dialog box because the messages can be forwarded to the message handlers in the window or dialog class using CToolCtrl::RelayEvent. Here is the rub, if pWnd points to a child window control (like yopur ownere drawn button), you have to resort to window subclassing (or some other method) in order to see the mouse messages going to the window and relay them to the tooltip control.  You must add this capability on your own.

I use Prosise's technique and add a subclassing feature to my devrive class. (the new functions are AddWindowToo(CWnd*, LPCTSTR) and AddRectTool(CWnd*,LPCTSTR, LPCRECT, UNIT)  ) that set up a TOOLINFO structure and calls SendMessage( );

Creating a tool from a child window control just requires the call m_ctlName.AddWindowTool(pWnd,"This is your custom Button"); or you the AddRectTool call from a rectange in a window.  Hope this helps.. Let me know if you need more details
0
 

Author Comment

by:alpar
ID: 1309597
Thanks for the assistance, but unfortunately I cannot derive
from CToolTipCtrl in order to solve my problem. Let me be more
specific:
I am using a CScrollView derived class, for which I have issued
'EnableToolTips'. This along with the 'TTN_NEEDTEXT' handler
work fine in all cases but a very specific one; I have created
an owner-drawn button, for which I would like to be able to
produce two different tooltips, depending on where on the button
the mouse cursor is. This, I think, would mean to be able to
'tell' the tooltip control used internally by CWnd's that they
should pop, when the cursor exited a known region on the button.
By overriding 'OnNCHitTest' I have managed to not allow the tip
to appear before the mouse cursor enters one of the two areas.
However, once the tip appears, I cannot make it 'go away',
because, I think, once it is shown it uses the window rectangle
internally to decide if it is still within valid area. I tried
to change that by overriding 'OnToolHitTest' at the view class
and from in there sending a message to the button, which should
decide itself if the point is within it. But this doesn't seem
to work. Could you suggest anything further, given the above
constraints?
0
 

Author Comment

by:alpar
ID: 1309598
Sorry about messing the answer grading, but I am very new at
this. Am I not going to get another chance at giving you points?
If that is the case, accept my apologies, because you really
did answer the question I asked in the first place (although
it was not the question I should have asked obviously!)

Alex
0
 
LVL 1

Expert Comment

by:kburns102197
ID: 1309599
Alex, Let me see the implementation of classes you have overidded & I will try to offer futher assistance. Provide as much detail as possible.. Don't worry about the points..its no big deal...kburns
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
conditional code and condition difference 9 65
isEverywhere  challenge 19 64
Thin secure Windows 10 5 48
Not needed 13 55
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

19 Experts available now in Live!

Get 1:1 Help Now