Tooltips for dialog controls


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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


  • ComboBoxEx

    Posted by Legacy on 11/02/2003 08: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?

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

    Posted by Legacy on 10/28/2003 08: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?


  • How to get "&" in ToolTips.

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

    Originally posted by: Rajkumar

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

  • Tooltip useful

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

    Originally posted by: Anand Kumar

    best is yet to be seen


  • Thanks a lot! I like it!

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

    Originally posted by: GZM

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

  • tooltips in CstatusBarCtrl ???

    Posted by Legacy on 06/02/2001 07: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.

  • Thanks Dave

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

    Originally posted by: Rajiv

    Thanks Dave,
    This helped me in my project!

  • ToolTips

    Posted by Legacy on 03/03/1999 08: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???

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

    Posted by Legacy on 01/14/1999 08: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?


  • RE:Tooltips for dialog controls

    Posted by Legacy on 11/06/1998 08: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.


  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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