Programming ToolTips

A ToolTip is a textbox that appears when a user taps and holds a stylus on a ToolTip control. In addition to the UI elements that can have ToolTips in Win32 programming, you can declare Palm-size PC static and button controls as ToolTip controls. You can also place ToolTip controls in dialog boxes and other application windows.

A ToolTip appears on the upper left side of the point where the user first taps the screen. You can use ToolTips to extend the name of a control. For example, a New button can have a ToolTip that displays “New Mail Message.” A ToolTip can also direct a user to Help files or printed documentation.

    To program a ToolTip

  1. Call SHInitExtraControls.

    This initializes the ToolTip control. If you are programming multiple ToolTip controls, you need to call SHInitExtraControls only once.

  2. Declare the ToolTip control in your resource file.
  3. Write the ToolTip control text in two sections.

    Separate the sections with a double tilde, or “~~”. The text before the double tilde is the text that appears on the control. The text after the double tilde is the text that appears in the ToolTip. This text can be up to 253 characters long. If you do not add any text after the double tilde, the shell displays “No Help provided” when the user accesses the control’s ToolTip.

The following code example shows how to declare a ToolTip control in a resource file.

CONTROL        "Static text~~This is a cool ToolTip\r2nd ToolTip 
            line",IDC_STATIC,"TTSTATIC",WS_VISIBLE,19,24,56,8

If the ToolTip is longer than the width of the screen, the ToolTip wraps to a new line. You can force a line break by placing the \r character within the ToolTip text. However, do not use \r as a first or last character. Also, do not use \r consecutively, such as \r\r. The following code example shows how to use the \r character in a control declaration of a resource file:

CONTROL    "CheckBox~~Cool Chkbox ToolTip",IDC_SAVE,"TTBUTTON",
            BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP,3,0,95,11

As with other window text, you can alter the ToolTip control text with SetWindowText. The following table shows the input values to use when calling SetWindowText. In the Input values column, hwndBtn refers to the handle of the target button.

Input values
Description
(hwndBtn, TEXT(“~~New ToolTip text”)) Changes the ToolTip text but keeps the current control text.
(hwndBtn, TEXT(“New Control Text”)) Keeps the current ToolTip text and changes the control text only.
(hwndBtn, TEXT(“New Control Text~~New ToolTip text”)) Changes the ToolTip text and the control text.
(hwndBtn, TEXT(“Old Test~~”)) Removes the ToolTip text and keeps the control text. After this call, the ToolTip still displays “No Help provided”.