• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Tooltips for a toolbar created at runtime

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?

Thanks!
Marisa
0
marisademeglio
Asked:
marisademeglio
  • 3
  • 2
1 Solution
 
jeremyeadamichCommented:
Hello,

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
   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;

   // 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...
      if(nID)
      {
         // convert nID into a string (contained in the string table)
         pTTT->lpszText = MAKEINTRESOURCE(nID);
         pTTT->hinst = AfxGetResourceHandle();

         // return success
         return(TRUE);
      }
   }

   // fail
   return(FALSE);
}

Jeremy
0
 
marisademeglioAuthor Commented:
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:

!m_wndDefaultToolbar.Create(WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
            rect, this, m_wndSidebar.GetDlgCtrlID() + 1)

thanks
marisa
0
 
jeremyeadamichCommented:
Hmmm,
Make sure that you call

    m_wndDefaultToolbar.EnableTooltips(TRUE);

 - although you might already be doing that...

Jeremy
0
 
marisademeglioAuthor Commented:
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!
marisa
0
 
jeremyeadamichCommented:
Right on, as long as it's working for you...

Jeremy
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now