HOWTO: Display More Than 80 Characters in a Tooltip Control

Last reviewed: February 6, 1998
Article ID: Q180646
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) on the following platforms:

        - Microsoft Windows NT
        - Microsoft Windows 95
    

SUMMARY

By default, the text displayed for an item in a tooltip control is limited to 80 characters. In some instances, you may want to have the tooltip display more than 80 characters.

MORE INFORMATION

To enable a tooltip control to display more than 80 characters, you need to specify that the text is available on a callback basis by setting the lpszText member of the TOOLINFO structure to LPSTR_TEXTCALLBACK when the tool is added to the tooltip control with the TTM_ADDTOOL message. When this is done, the tooltip control sends the parent window a WM_NOTIFY message with the TTN_NEEDTEXT notification code.

The TTN_NEEDTEXT notification's lParam is the address of a NMTTDISPINFO structure. One member of this structure is the szText member. szText is a character buffer that can hold up to 80 characters. Another member of this structure is the lpszText member that is the address of a character buffer that contains the text for the tool. By default, lpszText points to szText. When processing the TTN_NEEDTEXT notification, you can either copy the desired text to szText or change lpszText so that it points to a buffer other than szText. To allow the tooltip control to display more than 80 characters for a tool, you must set lpszText to point to a buffer that you allocate (and that contains the desired text).

After returning from the TTN_NEEDTEXT notification, the tooltip control allocates a buffer and copies the text into this new buffer. As a result, you can reuse the buffer for each TTN_NEEDTEXT notification. The buffer that you use must be a static, global, or dynamically-allocated buffer as long as it exists after returning from the notification. The buffer cannot be created on the stack because it will not be valid after returning from the message.

Add the TTS_NOPREFIX style to the tooltip control. You must do this because the tooltip control will limit the text length to 80 characters again when the control removes the "&" characters.

Keywords          : UsrCtl
Version           : WINNT:4.0; win95
Platform          : Win95 winnt
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 6, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.