Click here to Skip to main content
13,894,145 members
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 24 Aug 2007
Licenced CPOL

The Ultimate Toolbox COXToolTipCtrl Class

, 25 Aug 2007
Rate this:
Please Sign up or sign in to vote.
An extended tooltip control from the Ultimate Toolbox

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Source code and project files for this sample can be found in the samples\gui\ToolTipEx directory of the sample projects download.


COXToolTipCtrl is an extended tooltip control that allows multiline tooltips, plus extended tooltip text. Extended tooltip text is extra text that is displayed if the user clicks on the tooltip window. If the tooltip contains extended text (as well as a standard tooltip string) then the info window will contain a small arrow that prompts the user to click on the window. Once the window is clicked, the extended text is shown. If the window is clicked again then the window reduces to showing just the standard text.

The maximum width of the tooltips can be specified, and if the info text is too big to fit within these bounds then the text will be wrapped over multiple lines. The control also allows you to specify a different text and background colors for the tooltips, and the display font can also be changed.

This class is a direct replacement for the CToolTipCtrl class. It incorporates the entire API of the standard CToolTipCtrl, and introduces new features not found in the standard tooltip.

The control is used just like any other tooltip control. To use the tool, simply call Create(...) and specify the parent window of the tool, then add tools to the control using the AddTool(...) member function. E.g. (in a formview or a dialog):

        _T("Tooltip text\rThis is the extended\ntooltip text"));

where ID_CONTROL is the ID of a control.

To specify the extended text for a tooltip, simply append a '\r' after your tooltip text, and then append the extended tooltip info.

As with the standard tooltip control, you can specify the actual text for the tool at creation time (as shown above), or you can specify the LPSTR_TEXTCALLBACK value and provide a TTN_NEEDTEXT handler to return the text dynamically at runtime.

To handle the TTN_NEEDTEXT message, you will need to add a message handler in the parent window, and an entry in the message map, e.g. in you view or form.

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

BOOL CMyDlg::OnInitDialog()
    . . . . . . . . . . . . . . . . . . . . . . . . . .
BOOL CMyDlg::OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
    UINT nID = pNMHDR->idFrom;
    if (nID == IDC_CONTROL)    // Fill in the text buffer

        _tcscpy(pTTT->szText, _T("Tooltip text\rExtended tooltip text"));
        return TRUE;
    return FALSE;

You can also supply text in two alternate ways, either by supplying a string resource:

pTTT->hinst = AfxGetResourceHandle(); 
return TRUE;

or by supplying a pointer to the text:

pTTT->lpszText = _T("Tooltip text\rExtended tooltip text");
return TRUE;

Newline characters ('\n') can be embedded anywhere within the text or extended text to produce a multiline tooltip. If the width of the tooltip window is specified using SetMaxTipWidth() then the tooltip text will be wrapped to this length, and if necessary displayed on more than one line.

To change the font of the tooltips, simply use the SetFont() member function.

The GetToolInfo/SetToolInfo functions, and the HitTest functions are very similar to the CToolTipCtrl versions except that they use a OXTOOLINFO structure instead of a TOOLINFO structure. This structure is defined as:

#if (_WIN32_IE < 0x0300)
    LPARAM lParam;
    //Application defined value 

    //that is associated with the tool

    int nWidth; //Width of box, or 0 for default

    COLORREF clrTextColor; //text color

    COLORREF clrBackColor; //background color


and so is very similar to the standard TOOLINFO, and is used in the same way, with the exception that the uFlags member is not (yet) used.

To change the color of an individual tip, use the GetToolInfo/SetToolInfo functions.

if (m_toolTip.GetToolInfo(ToolInfo, GetDlgItem(IDC_CONTROL)))
    ToolInfo.clrBackColor = RGB(255, 255, 255);
    ToolInfo.clrTextColor = RGB( 0, 0, 255);


#include <span class="code-string">"OXToolTipCtrl.h"</span>

Source code files:

  • OXToolTipCtrl.cpp

A complete class reference for the COXToolTipCtrl is available in the compiled HTML help documentation.


Initial CodeProject release August 2007.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

458 members

You may also be interested in...

Comments and Discussions

BugBug was found Pin
AndSqr31-Aug-16 1:43
professionalAndSqr31-Aug-16 1:43 
GeneralMy vote of 4 Pin
tzleo11-Jul-13 22:49
membertzleo11-Jul-13 22:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190306.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid