Condividi tramite


Handling TTN_NEEDTEXT Notification for Tool Tips

As part of enabling tool tips, you handle the TTN_NEEDTEXT message by adding the following entry to your owner window's message map:

ON_NOTIFY_EX(TTN_NEEDTEXT, 0, &CMyDialog::OnTtnNeedText)
  • memberFxn
    The member function to be called when text is needed for this button.

Note that the ID of a tool tip is always 0.

Declare your handler function in the class definition as follows:

afx_msg BOOL OnTtnNeedText(UINT id, NMHDR *pNMHDR, LRESULT *pResult);

where the italicized parameters are:

  • id
    Identifier of the control that sent the notification. Not used. The control id is taken from the NMHDR structure.

  • pNMHDR
    A pointer to the NMTTDISPINFO structure. This structure is also discussed further in The TOOLTIPTEXT Structure.

  • pResult
    A pointer to result code you can set before you return. TTN_NEEDTEXT handlers can ignore the pResult parameter.

As an example of a form-view notification handler:

BOOL CMyDialog::OnTtnNeedText(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
{
   UNREFERENCED_PARAMETER(id);

   NMTTDISPINFO *pTTT = (NMTTDISPINFO *) 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)
      {
         _stprintf_s(pTTT->szText, sizeof(pTTT->szText) / sizeof(TCHAR), 
            _T("Control ID = %d"), nID);
         pTTT->hinst = AfxGetResourceHandle();
         bRet = TRUE;
      }
   }

   *pResult = 0;

   return bRet;
}

Call EnableToolTips (this fragment taken from OnInitDialog):

EnableToolTips(TRUE);

See Also

Concepts

Tool Tips in Windows Not Derived from CFrameWnd

Change History

Date

History

Reason

July 2010

Updated code example.

Customer feedback.