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

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

Top White Papers and Webcasts

  • 10 Rules that Make or Break Enterprise App Development Projects In today's app-driven world, application development is a top priority. Even so, 68% of enterprise application delivery projects fail. Designing and building applications that pay for themselves and adapt to future needs is incredibly difficult. Executing one successful project is lucky, but making it a repeatable process and strategic advantage? That's where the money is. With help from our most experienced project leads and software engineers, …

  • As more and more organizations migrate to the cloud, many are faced with hidden costs emerging from unexpected places. Two non-obvious and non-trivial factors can drive up costs. First are separate charges for everything from server memory to intrusion detection. Second are the high personnel costs for early-generation, manually operated clouds. These costs can rack up quickly, creating total cost of ownership (TCO) surprises. Keeping TCO low in the cloud is essentially a matter of management strategy. IT …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds