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

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)



Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As virtualization becomes the norm throughout organizations of nearly all sizes, and as more organizations look to private cloud solutions, IT decision makers are increasingly in need of ways to keep storage costs and complexity under control in the face of often-runaway virtual machine (VM) sprawl. Application-aware storage is designed to help achieve these important goals. Read this white paper to learn how application-aware storage allows you to gain VM-level visibility into application performance and …

  • Relying on outside companies to manage your network and server environments for your business and applications to meet the needs and demands of your users can be stressful. This is especially true as many Managed Hosting organizations fail to meet their service level agreements. Read this Forrester total economic impact report and learn what makes INetU different and how they exceed their customers' managed hosting expectations.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date