DOC: How to Display Tool Tips After Calling EnableToolTipsLast reviewed: July 31, 1997Article ID: Q140595 |
The information in this article applies to:
SUMMARYThe Microsoft Foundation Classes (MFC) 4.x documentation states that you can call the CWnd::EnableToolTips function to enable tool tips for the child controls of a window. For example, this function can be used to display tool tips for all the controls on a Form View. However, simply calling this function is not sufficient. In an application built with MFC 4.x, tool tips for your child controls will not display correctly unless you provide a handler for the TTN_NEEDTEXT tool tip notification. This documentation error has been fixed in Visual C++ version 5.0.
MORE INFORMATIONThe default tool tips provided for your windows by EnableToolTips do not have text associated with them. In order 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. Tool tips are displayed for tool bar buttons without any extra effort. This is because the parent of the tool bar is derived from CFrameWnd, which has a default handler for the TTN_NEEDTEXT notification. This handler is designed for handling TTN_NEEDTEXT notifications from tool tip controls associated with tool bar buttons. This handler is not called when the notification is sent from a tool tip control associated with a child control in a window that is not a CFrameWnd such as a control on a dialog box or a form view. Therefore, it is necessary for the user to provide a handler function for the TTN_NEEDTEXT notification message in order to display tool tips for child controls.
Steps to Enable Tool Tips for Child ControlsTo enable tool tips for the child controls of a window (such as the controls on a form view), follow these steps:
Sample Code
// Each control on the form view has an associated // string resource with the same ID in the string table of // this application. // Message Map for CFormView derived class BEGIN_MESSAGE_MAP(CMyFormView, CFormView) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify) END_MESSAGE_MAP() //Notification handler - add entry to class definition BOOL CMyFormView::OnToolTipNotify(UINT id, NMHDR *pNMH, LRESULT *pResult) { TOOLTIPTEXT *pText = (TOOLTIPTEXT *)pNMH; int control_id = ::GetDlgCtrlID((HWND)pNMH->idFrom); if(control_id) { pText->lpszText = MAKEINTRESOURCE(control_id); pText->hinst = AfxGetInstanceHandle(); return TRUE; } return FALSE; } void CKbtestView::OnInitialUpdate() { CFormView::OnInitialUpdate(); EnableToolTips(TRUE); } REFERENCESFor further information on how commands such as WM_NOTIFY are routed, see Programming with MFC Overview, Working with Messages and Commands, How the Framework Calls a Handler, Command Routing in Books Online. For further information on how to handle a WM_NOTIFY message such as TTN_NEEDTEXT, see Tech Note 61: ON_NOTIFY and WM_NOTIFY Messages. Keywords : MfcMisc MfcUI vcbuglist400 kbcode kbprg kbui Technology : kbMfc Version : 4.0 4.1 4.2 Platform : NT WINDOWS Issue type : kbdocerr Solution Type : kbdocfix |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |