Export (0) Print
Expand All
Expand Minimize

CWnd::EnableToolTips

Enables tool tips for the given window.

BOOL EnableToolTips(
   BOOL bEnable = TRUE
);

Parameters

bEnable
Specifies whether the tool tip control is enabled or disabled. TRUE enables the control; FALSE disables the control.

Return Value

TRUE if tool tips are enabled; otherwise FALSE.

Remarks

Override OnToolHitTest to provide the TOOLINFO struct or structs for the window.

Note   Some windows, such as CToolBar, provide a built-in implementation of OnToolHitTest.

See TOOLINFO in the Platform SDK for more information on this structure.

Simply calling EnableToolTips is not enough to display tool tips for your child controls unless the parent window is derived from CFrameWnd. This is because CFrameWnd provides a default handler for the TTN_NEEDTEXT notification. If your parent window is not derived from CFrameWnd, that is, if it is a dialog box or a form view, tool tips for your child controls will not display correctly unless you provide a handler for the TTN_NEEDTEXT tool tip notification. See Tool Tips.

The default tool tips provided for your windows by EnableToolTips do not have text associated with them. To retrieve text for the tool tip to display, the TTN_NEEDTEXT notification is sent to the tool tip control's parent window just before the tool tip window is displayed. If there is no handler for this message to assign some value to the pszText member of the TOOLTIPTEXT structure, there will be no text displayed for the tool tip.

Example

BEGIN_MESSAGE_MAP(CMyView, CView)
   ...
   ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
   ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
END_MESSAGE_MAP()

void CMyView::OnInitialUpdate() 
{
   CView::OnInitialUpdate();
   
   CEdit* pEdit = new CEdit;
   pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
      CRect(10, 10, 100, 100), this, 111);
   EnableToolTips(TRUE);   // enable tool tips for view
}

//Notification handler
BOOL CMyView::OnToolTipNotify(UINT id, NMHDR *pNMHDR,
   LRESULT *pResult)
{
   // need to handle both ANSI and UNICODE versions of the message
   TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
   TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
   CString strTipText;
   UINT nID = pNMHDR->idFrom;
   if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
      pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
   {
      // idFrom is actually the HWND of the tool
      nID = ::GetDlgCtrlID((HWND)nID);
   }

   if (nID != 0) // will be zero on a separator
      strTipText.Format("Control ID = %d", nID);

   if (pNMHDR->code == TTN_NEEDTEXTA)
      lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
   else
      ::MultiByteToWideChar( CP_ACP , 0, strTipText, -1, pTTTW->szText, sizeof(pTTTW->szText) );
   *pResult = 0;

   return TRUE;    // message was handled
}

See Also

CWnd Overview | Class Members | Hierarchy Chart | CWnd::CancelToolTips | CWnd::OnToolHitTest | CToolBar | TOOLINFO

Show:
© 2015 Microsoft