Tooltip Control (without MFC)

Environment: Visual C++ 6 SP3

MFC Tool tip control(CToolTipCtrl) is easy to use with a window, such as
a child window, or an application-defined rectangular area within a window’s
client area. However, in some situations you may not know in advance for which
controls or rectangle area you will be displaying the tool tip. In this case,
you have to dynamically display the tool tip depending on where your mouse
position is. For e.g. you may have a window which display some graphics and
you may want to display the tool tip on the graphics depending on where the
mouse position is.

I developed a MFC look alike tool tip control, which is easy to use in this
kind of scenarios. Just create the control, set the text and call the show
method and see it working.

Steps to use the tool tip control in your code?

  1. Create tool tip by calling Create() method
  2. Set tool tip test by calling SetText() method
  3. Call Show() to display tool tip

When to use this control?

For most purposes MFC tool tip control should satisfy your need. Use
this control only when you need to dynamically display tool tip at a
given coordinate.


This is a bare minimum tool tip control and the following additional
functionalities can be easily added to make it more useful and production

  • Support for multi line tool tip text
  • Automatically killing tool tip after few seconds(Hint: Use timer)
  • Positioning tool tip so that it won’t go beyond desk top window

Sample Code Demonstrating how to use CToolTip2

File: YourWnd.h

#include "tooltip2.h"
CYourWnd::public CWnd
//Other code
CToolTip2 m_ToolTip;
 afx_msg void OnMouseMove( UINT nFlags, CPoint point );

File: YourWnd.cpp

#include "YourWnd.h"

//Other initialization

CYourWnd::OnMouseMove ( UINT nFlags, CPoint point ))
m_ToolTip .SetText(GetDescription(point));
CWnd::OnMouseMove(nFlags, point);

//NOTE: Implement your own GetDescription.
//This is provided just for illustration.
CString CYourWnd::GetDescription(CPoint point)
if ( point.x > 100 && point.x < 200 ) && (point.y > 100 && point.y < 300)
 return "Daddy";
else if ( point.x > 200 && point.x < 275) && (point.y > 130 && point.y < 280)
 return "Mummy";
 return "Kiddy";


Download source - 3 Kb

More by Author

Must Read