Balloon Tooltips | CodeGuru

Balloon Tooltips

and enhanced by Guy Brousseau and Greg Gagnaux. This class, CTooolTipWnd is useful if you want tooltips to look like an ellipse rather than the standard rectangle as shown in the image below. Usage is somewhat similar to MFC CToolTipCtrl. To use CTooolTipWnd in an MFC application, you have to perform the following steps 1. […]

Written By
CodeGuru Staff
CodeGuru Staff
Jul 4, 1999
3 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

and enhanced
by Guy Brousseau and
Greg Gagnaux.

This class, CTooolTipWnd is useful if you want tooltips to
look like an ellipse rather than the standard rectangle as shown
in the image below.

Usage is somewhat similar to MFC CToolTipCtrl.

To use CTooolTipWnd in an MFC application, you have to perform
the following steps

1. Add ToolTipWnd.cpp to your
project.

2. #include "ToolTipWnd.h"
in the header file of the class, where you want tooltips.

3. Add a variable in the class.

CToolTipWnd m_BalloonToolTip;

3. In OnInitDialog (if it is a dialog) or OnInitialUpdate (if
it is a formview) add the following code

m_BalloonToolTip.Create(this);

m_BalloonToolTip.AddTool(GetDlgItem(<id>),
<text>, [text color]);

eg.

m_BalloonToolTip.AddTool(GetDlgItem(IDC_EDIT1),"Tooltip",
RGB(255,0,0));

Third parameter is optional. If it is not given the default
text color ( RGB(0,0,0) ) is used. The default text color can
also be set using the public function SetDefTextColor.

4. Override PreTranslateMessage and add the following code


if(m_BalloonToolTip)
m_BalloonToolTip.RelayEvent(pMsg);

Here is a list of all the public methods and variables.

  • void AddTool(CWnd *pWnd, CString
    strText, COLORREF clrTextColor=NULL);
  • void SetWidth(int iWidth)
    This function is used for setting the width of the
    tooltip window. Default is 100
  • void SetHeight(int iHeight)
    This function is used for setting the height of
    the tooltip window. Default is 60
  • void SetBkColor(COLORREF clrRef)
    To Set the background color
    of the tooltip window. Default is Light yellow (on a 256
    color display this will look dithered.
  • void SetFrameColor(COLORREF clrRef)
    To set the border color of
    the window. Default is Blue
  • void SetDefTextColor(COLORREF
    clrRef)
    The default textcolor is
    black, you can change it using this function.
  • void SetFontHeight(int iHeight) {
    m_iFontHeight = iHeight; }
    To set the font size.
    Default is 14.
  • void SetFontName(CString
    strFontName) { m_strFontName = strFontName; }
    To the font name. Default is
    Arial.

The tooltip text will be wrapped iniside the window if it
exceeds one line otherwise it will be centered horizontally and
vertically.

Enhancements

Enhancements by Guy Brousseau

Guy Brousseau has enchanced this control with the following corrections
and additions:

Here is the summary of changes (addressing two posted comments) extracted
from the code

  • Add TIMER support (0 if no timer wanted)
  • DON’T GET CLIPPED around screen corners (although incomplete).
  • Corrected a bug when m_stuck is not set and mouse moves over the tooltip, it moved
  • Corrected a bug when you jumped quickly into a control and land onto a tooltip, the mouse moves and click were not forwarded
  • Trap Non-client messages for mouse move and button click (cf. scrollbars in edit controls)
  • Replace tool in lookup table if inserted more than once
  • Explicitly display the tooltip by programmation request (rather than mouse move)
  • All revamped (simplified and commented) to be better understandable (sorry, but I must stick to local programming style…)

Guy thanks his boss, Jean Ctti, who joyfully granting him the 2 days necessary for this mission.

Advertisement

Enhancements by Greg Gagnaux

Greg Gagnaux has enchanced this control with the following additions:

Here is the summary of changes (one of the posted comments)

  • Added a second timer to allow a short delay before the tooltip is displayed. (Defaults to 1 second)

Download source (5.7 Kb)

Download demo (36 Kb)

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.