Tooltips for a toolbar created at runtime

Posted on 2005-04-05
Last Modified: 2013-11-20
Hi experts,

I have a toolbar that I'm creating at runtime.  It lives inside a rebar which lives inside a CMDIFrameWnd control.
How do I enable tooltips for this toolbar?  

I see two approaches:

1. catch the tooltip notify event and set the text myself
but how do i know which button the user selected?

2. enable tooltips on the toolbar and they should automatically show up
but this isn't working, i think because i'm not explicitly setting a tooltip for each button.  i do assign a string to the buttons, but this apparently doesn't get used for the tooltips.

Any ideas?

Question by:marisademeglio
    LVL 3

    Accepted Solution


    When you say you are assiging a string to the button, I'm assuming that you are referring to the text on the button. Try this:

    Open the resources tab and select the folder labeled "String Table". Add entries here for each of your button IDs.

    If you are using a CToolBar derived class that you wrote yourself, you can also handle the TTN_NEEDTEXT message and provide tooltip text yourself.

    BOOL CMyDlgBar::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
       // Cast the NMHDR pointer to a tooltiptext struct

       // Get the control ID
       UINT nID = pNMHDR->idFrom;

       // Make sure we should do this...
       if (pTTT->uFlags & TTF_IDISHWND)
          // idFrom is actually the HWND of the tool
          nID = ::GetDlgCtrlID((HWND)nID);

          // If nID is valid...
             // convert nID into a string (contained in the string table)
             pTTT->lpszText = MAKEINTRESOURCE(nID);
             pTTT->hinst = AfxGetResourceHandle();

             // return success

       // fail


    Author Comment

    Thanks for the code.    Maybe you could help me figure this out -

    the statement "if (pTTT->uFlags & TTF_IDISHWND)" always turns out false.

    what does TTF_IDISHWND rely upon?  do I need to create the toolbar with any special parameters?

    Right now, my toolbar class is derived from CToolBarCtrl, and the toolbar is created like this:

                rect, this, m_wndSidebar.GetDlgCtrlID() + 1)

    LVL 3

    Expert Comment

    Make sure that you call


     - although you might already be doing that...


    Author Comment

    It works now...
    I changed the line to
    if (pTTT->uFlags && TTF_IDISHWND)
    (&& instead of &)

    The line:  
    nID = ::GetDlgCtrlID((HWND)nID);

    always gave me zero, but I found a way around that internally.

    Thanks for your help!
    LVL 3

    Expert Comment

    Right on, as long as it's working for you...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    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.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now