Tooltips for dialog controls

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

Here's a little trick I use to get tooltips into a dialog quickly. I usually put this code into the OnInitDialog. It allows me to easily add tooltips to any dialog quickly.

Add a member to the CDialog or CWnd derived class in the header like:
CToolTipCtrl    CTTDialog :: m_ToolTip;
In the OnInitDialog or OnInitialUpdate, add:
m_ToolTip.Create (this);
m_ToolTip.Activate (TRUE);

CWnd*    pWnd = GetWindow (GW_CHILD);
while (pWnd)
{
    int nID = pWnd->GetDlgCtrlID ();
    if (nID != -1)
    {
        m_ToolTip.AddTool (pWnd, pWnd->GetDlgCtrlID ());
    }
    pWnd = pWnd->GetWindow (GW_HWNDNEXT);
}
To add a tooltip to a control, just add a string resource using the same ID as the control to get the tip. If I wanted the OK button to have a tip, I would add a string resource for IDOK.

Also do not forget to put the following code to you dialog class:
BOOL CTTDialog :: PreTranslateMessage(MSG* pMsg) 
{
    if (m_hWnd)
    {
        m_ToolTip.RelayEvent (pMsg);
        return CDialog::PreTranslateMessage(pMsg);
    }
    return (FALSE);
}
That's it.

Last updated: 18 May 1998



Comments

  • ComboBoxEx

    Posted by Legacy on 11/02/2003 12:00am

    Originally posted by: Walter Hahn

    This method works perfect but not with the ComboBoxEx control. Any idea how to get it work with this control?

    Reply
  • Cant get this to work in Visual C++.NET (7.0)

    Posted by Legacy on 10/28/2003 12:00am

    Originally posted by: Mike Pliam

    I can't get this to work using C++ 7.0.  I've even tried Corey's fix and putting 'EnableToolTips(TRUE);' in the OnInitDialog() member.
    
    

    Any other's had this problem or know how to fix it?

    Mike

    Reply
  • How to get "&" in ToolTips.

    Posted by Legacy on 11/27/2002 12:00am

    Originally posted by: Rajkumar

    All are fine..But how to get ampersand in tooltips.

    Reply
  • Tooltip useful

    Posted by Legacy on 04/09/2002 12:00am

    Originally posted by: Anand Kumar


    best is yet to be seen

    thanks

    Reply
  • Thanks a lot! I like it!

    Posted by Legacy on 01/30/2002 12:00am

    Originally posted by: GZM

    Your method is very simple!
    
    And she is very useful!
    Thank you!

    Reply
  • tooltips in CstatusBarCtrl ???

    Posted by Legacy on 06/02/2001 12:00am

    Originally posted by: amit gupta

    How can i use the tooltips when i use a CStatusBarCtrl status bar .how should i trap the event when the mouse hovers over a button or a menu item.Problem is that i am unable to use CStatusBar with dialogs.Hence i am using CStatusBarCtrl .

    Can anybody suggest how to use a status bar in a dialog
    Please.I am ready to try anything.
    Waiting...

    Reply
  • Thanks Dave

    Posted by Legacy on 01/30/2001 12:00am

    Originally posted by: Rajiv

    Thanks Dave,
    This helped me in my project!

    Reply
  • ToolTips

    Posted by Legacy on 03/03/1999 12:00am

    Originally posted by: sahu

    It seems to work pretty well, but the tooltip does not show up when a
    control is disabled. Any ideas???

    Reply
  • How do I get tooltips to work in a Modal less dialog

    Posted by Legacy on 01/14/1999 12:00am

    Originally posted by: Aaron Nielsen

    When I try to get tool tips to work in a modal dialog using the tooltip control and overriding on
    PreTranslate message it works as described, but when I make the dialog Modal less it doesn't display any
    tooltips.  The PretranslateMessage method never gets called.  Any ideas on how to get this to work?
    
    

    Thanks,
    Aaron.

    Reply
  • RE:Tooltips for dialog controls

    Posted by Legacy on 11/06/1998 12:00am

    Originally posted by: Corey Frost

    This will work fine unless you display a modal dialog from the dialog you have added tooltips to. This is a Microsoft bug and can be found in the MS knowledge base article ID: Q143313. This affects MS Visual C++ versions 4 - 6.0. The fix is simple, just add a call to activate your tooltip control prior to calling the relayevent method in your PreTranslateMessage implementation.

    ToolTip.Activate(TRUE);
    ToolTip.RelayEvent(pMsg);

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date