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

  • Live Event Date: May 6, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT Where are you in your plans to adopt Disaster Recovery-as-a-Service? Are you just getting started? Fighting an uphill battle with management? At Cisco, Zerto and iland, we've seen it all – from the early adopters who excitedly rushed to implement DRaaS with us nine years ago to the IT folks dragging their business leaders into the future. With our years of experience, we've learned there are six types of DRaaS leaders – but which type …

  • Live Event Date: May 18, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT While the idea of using facial and or gesture recognitions to create a modern, intuitive game seems attractive, some developers may want to leverage Unity 3D as a way to accelerate their development. There are many different ways in which Intel and Unity Technologies have been working together to helps speed the develop of games with the Intel® RealSense™ SDK (Software Developer Kit), so come hear from a panel of experts on what we've done …

Most Popular Programming Stories

More for Developers

RSS Feeds

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