locked
tooltips on toolbar buttons RRS feed

  • Question

  • Hi,

    I have a MFC Dialog based application. I added a toolbar to the dialog. I don't know how to enable tooltips to the buttons.
    I set the toolbar's property to allow tooltips. And from the resource, in prompt I wrote text to be showed as tooltip but it still doesn't show up.
    What am I missing here?

    Thank you.
    Tuesday, May 12, 2009 4:23 PM

Answers

  • You can do it in two steps programmatically if you want.
    [#1] call enable tootip function.
    m_wndToolBar.EnableToolTips(TRUE);

    [#2] Handle a notify message
    ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnTooltipHandler)

    BOOL CMainFrame::OnTooltipHandler(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
    {
        TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
        UINT nID = static_cast<int>(pNMHDR->idFrom);
        CString strTip = _T("");
    
        switch (nID)
        {
        case ID_BTN_xxx :
            strTip = "tooltip text";
            break;
         ....
        }
    
       _tcscpy(pTTT->szText, strTip.GetBuffer(0));
    }
    
    
    That's all...
    • Edited by Anand K Reddy Tuesday, May 12, 2009 6:35 PM
    • Marked as answer by gsumm Tuesday, May 12, 2009 9:11 PM
    Tuesday, May 12, 2009 6:25 PM

All replies

  • You can do it in two steps programmatically if you want.
    [#1] call enable tootip function.
    m_wndToolBar.EnableToolTips(TRUE);

    [#2] Handle a notify message
    ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnTooltipHandler)

    BOOL CMainFrame::OnTooltipHandler(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
    {
        TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
        UINT nID = static_cast<int>(pNMHDR->idFrom);
        CString strTip = _T("");
    
        switch (nID)
        {
        case ID_BTN_xxx :
            strTip = "tooltip text";
            break;
         ....
        }
    
       _tcscpy(pTTT->szText, strTip.GetBuffer(0));
    }
    
    
    That's all...
    • Edited by Anand K Reddy Tuesday, May 12, 2009 6:35 PM
    • Marked as answer by gsumm Tuesday, May 12, 2009 9:11 PM
    Tuesday, May 12, 2009 6:25 PM
  • Is this the simplest way available to set tooltips?

    I'm surprised that there is no way to do this simple task from the resource view directly.
    Tuesday, May 12, 2009 8:43 PM
  • Also, what does prompt - "Specifies the ToolTip text that will be displayed when the button is passed over" mean?

    OR

    How does prompt help set the tooltips?
    Tuesday, May 12, 2009 9:03 PM
  • It doesn't display as a tooltip rather it will display in the status bar when you move the mouse over the button.

    Anand
    Tuesday, May 12, 2009 9:08 PM
  • Thanks anyway Anand.

    If anyone is going through this post needs more help in setting tooltips, there is a sample application dlgcbr32 when you download the C++ sample applications.

    If you are programming with MFC feature pack 2008, there is a sample called DlgToolTips which explains how to use CMFC tool tip control.
    Tuesday, May 12, 2009 9:10 PM