How to enable tool tip support for all the child controls of a window

14 07 2009

description5

 

 

Sometimes we really want to enable tool tip support for all the child controls of our window or dialog.

HowCanIDoIt1

 

 

To enable tool tips for the child controls you need to do the following things.

  • 1) Call EnableToolTips MFC function for the window you want to provide tool tips.
  • 2) Provide a string for each control in your TTN_NEEDTEXT notification handler.

MyCodeSnippet

 

 

afx_msg BOOL OnTtnNeedText(UINT id, NMHDR *pNMHDR, LRESULT *pResult);
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, CMyDialog::OnTtnNeedText)
BOOL CMyDialog::OnTtnNeedText(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
{
   UNREFERENCED_PARAMETER(id);
  
   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
   UINT_PTR nID = pNMHDR->idFrom;
   BOOL bRet = FALSE;
  
   if (pTTT->uFlags & TTF_IDISHWND)
   {
      // idFrom is actually the HWND of the tool
      nID = ::GetDlgCtrlID((HWND)nID);
      if(nID)
      {
         TCHAR szBuff[64];
         _stprintf_s(szBuff, sizeof(szBuff) / sizeof(TCHAR),
            _T("Control ID = %d"), nID);
         pTTT->lpszText = szBuff;
         pTTT->hinst = AfxGetResourceHandle();
         bRet = TRUE;
      }
   }
   *pResult = 0;
  
   return bRet;
}
Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: