Click here to Skip to main content
15,176,561 members
Articles / Desktop Programming / MFC
Posted 7 Dec 1999


74 bookmarked

A multiline extended tooltip control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (20 votes)
7 Dec 1999CPOL
A drop-in multiline extendable tooltip control

sample image 1  sample image 2 

COXToolTipCtrl Overview

DundasThis class is a free sample from Dundas Software's Ultimate Toolbox. Copyright © Dundas Software Ltd. 1997-1999, All Rights Reserved

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. eg. (In a formview or dialog)

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

where ID_CONTROL is the ID of a control.

To specify 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, eg. in you view or form


BOOL CMyDlg::OnInitDialog()
    tooltip.AddTool(GetDlgItem(IDC_CONTROL), LPSTR_TEXTCALLBACK);

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 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

(_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);


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


About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs CodeProject. He is also co-founder of Developer Media and ContentLab.IO. He's been programming since the 80's and has been, in various guides, an astrophysicist, bacyard mechanic, mathematician, physicist, breeder of carnivorous plants, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer.

His programming experience includes C/C++, C#, SQL, MFC, ASP.NET, TypeScript and far, far too much FORTRAN. He has worked on PocketPCs, Old mainframes, new Macs, cheap phones, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He is kind to small animals and has a soft spot for cheesecake.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is obsessively into road cycling, physiology, occasionally snowboarding and rock climbing, and wishes he were a storm chaser.

Comments and Discussions

BugRE: Not working in VS2008 Pin
mla15429-Apr-13 10:07
Membermla15429-Apr-13 10:07 
AnswerRe: RE: Not working in VS2008 Pin
mla15429-Apr-13 10:25
Membermla15429-Apr-13 10:25 
QuestionIs possibility to add an image to tool tip? Pin
mrowca15-Jan-10 10:29
Membermrowca15-Jan-10 10:29 
GeneralMy vote of 1 Pin
Nisheeth White15-Oct-09 1:39
MemberNisheeth White15-Oct-09 1:39 
GeneralNot necessary for multiline tool tips Pin
richardwhitehead17-Oct-07 4:08
Memberrichardwhitehead17-Oct-07 4:08 
GeneralHandling Overlapping Objects... Pin
embeddedDude15-Feb-07 6:35
MemberembeddedDude15-Feb-07 6:35 
Questioncompile time error in my library file Pin
mailtochandra2000@yahoo.com8-Jan-07 23:23
Membermailtochandra2000@yahoo.com8-Jan-07 23:23 
QuestionAny way to have tooltips longer than 80 characters long with this? Pin
thready3-Nov-06 15:02
Memberthready3-Nov-06 15:02 
QuestionHow to use as tooltip for MDI App toolbars ? Pin
ana_v12311-Apr-06 23:50
Memberana_v12311-Apr-06 23:50 
QuestionCan this be used with app's taskbar button tooltip ??? Pin
ana_v12311-Apr-06 14:00
Memberana_v12311-Apr-06 14:00 
GeneralLink on tooltip Pin
scvarz29-Mar-05 23:04
Memberscvarz29-Mar-05 23:04 
Generalproblem with WS_EX_TOPMOST Pin
rpar10-Mar-05 22:12
Memberrpar10-Mar-05 22:12 
Generalmissing UpdateTipText Pin
SGarratt28-Oct-04 15:33
MemberSGarratt28-Oct-04 15:33 
GeneralJust another bugfix Pin
Marek Konopka20-Feb-04 12:30
MemberMarek Konopka20-Feb-04 12:30 
GeneralAnother Bug Fix Pin
RussH5-Jan-04 11:08
MemberRussH5-Jan-04 11:08 
GeneralRe: Another Bug Fix Pin
ziyoo30-Mar-04 17:18
Memberziyoo30-Mar-04 17:18 
GeneralBug Fix Pin
PJ Arends2-Nov-03 4:43
professionalPJ Arends2-Nov-03 4:43 
GeneralRe-Position ToolTip Text Pin
Brian Krzys21-Oct-03 5:36
MemberBrian Krzys21-Oct-03 5:36 
GeneralFeature Request/Consideration Pin
alan9316-Oct-03 10:31
Memberalan9316-Oct-03 10:31 
Generalresize Pin
botsjeh14-Oct-03 11:32
Memberbotsjeh14-Oct-03 11:32 
QuestionWhat does it mean Pin
KaЯl17-Sep-03 0:01
MemberKaЯl17-Sep-03 0:01 
AnswerRe: What does it mean Pin
Chris Maunder17-Sep-03 4:17
cofounderChris Maunder17-Sep-03 4:17 
GeneralThanks for your answer Pin
KaЯl17-Sep-03 4:30
MemberKaЯl17-Sep-03 4:30 
GeneralProblems with resize controls Pin
KondriSergey27-Jun-03 4:00
MemberKondriSergey27-Jun-03 4:00 
QuestionHow to Hook TTN_NEEDTEXT? Pin
zhang lu27-Apr-03 23:39
Memberzhang lu27-Apr-03 23:39 

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.