Solved

How to use CToolTipCtrl class to display my own tool tips?

Posted on 1998-12-17
4
1,746 Views
Last Modified: 2013-11-20
I need to display different messages which dinamically change and are not set in resources.  I need to do this when mouse pointer moves over a certain area of a dialog.
I declare local CToolTipCtrl variable, create tool tip control and than I try different ways to display my message; unsuccessfuly.

I'd appreciate any suggestions.

Seweryn S. Makosa
0
Comment
Question by:nyrewes
  • 2
4 Comments
 

Author Comment

by:nyrewes
Comment Utility
Edited text of question
0
 

Author Comment

by:nyrewes
Comment Utility
Edited text of question
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 total points
Comment Utility
Use AddTool/UpdateTipText to change the text.  You can pass a string or resource id.  This function is overloaded (there are 2 versions : look it up in the help)

Presumably you are doing the relay events stuff

The steps are :-
1. Add tooltip member variable (CToolTipCtrl) to your dialog class, say m_ToolTip
2. OnInitDialog do
      // set tooltips
      m_ToolTip.Create (this);
            m_ToolTip.Activate (TRUE);
            m_ToolTip.AddTool( &m_btnPrev, IDS_TTPREV ) ;
            m_ToolTip.AddTool( &m_btnNext, IDS_TTNEXT ) ;
            m_ToolTip.AddTool( &m_btnFirst, "Some Text" ) ;

The first parameter of the control is the CWnd (or derived from CWnd - example:CButton,CEdit etc) from the control you want to associate the tip with, second is the resource id, or there's an overloaded version of AddTool which takes a string parameter

3. PreTranslate message
BOOL CTComply::PreTranslateMessage(MSG* pMsg)
{
    if (m_hWnd)    
      {
        m_ToolTip.RelayEvent (pMsg);
            return CDialog::PreTranslateMessage(pMsg);
      }
    return (FALSE);
            
}


4. For an area on a dialog containing no visible controls, I suggest you create  a dummy static control at the correct location, and bind a CStatic member variable to it.  If the dummy control has no text, it will be invisible to the user, so it will look like the tooltip comes from the dialog background.
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
You can set text of tooltips dynamically at runtime in a TTN_NEEDTEXT message handler.

hope that helps
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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