DataTip

This class shows how I went about implementing my own tooltip window when I had trouble getting the standard Tooltips to provide the functionality I wanted. The attached code readily demonstrates the concepts of defining your own windows for use with MFC, installing keyboard hooks, and handling the correct clean-up of the system on completion (note the static methods and instance counting). The windows use the same colour scheme as Tooltips under Win95/NT (COLOR_INFOBK + COLOR_INFOTEXT) but you can choose your own colours should you wish (see the OnPaint method).

The class uses the standard two-stage MFC creation process. You use the class by defining an instance of the class in your view/dialog/etc and then calling the Create method passing it a pointer to the parent window (normally in your OnInitialUpdate or OnInitDialog methods).

You then handle the OnMouseMove event and call the Set method passing it a display point and display string. If the mouse remains static for the pre-defined delay time (set via SetDelay) then a tip window will be displayed at the appropiate point. Pressing a key, pressing a mouse button, or moving the mouse outside of a pre-defined are will remove the tip window from the display.

Example:

class CMyView : public CView
{
	:
	SIMDataTip m_datatip;
	:
};

void CMyView::OnInitialUpdate()
{
	CView::OnInitialUpdate();

	// enable datatips for this window
   	m_datatip.Create(this);
        :
        :
}

void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
	CView::OnMouseMove(nFlags, point);

	// intialise the datatip for this point
	m_datatip.Set(point, "message");
}

The tip window can be turned on and off by calling the On method. It's current status is available via the IsOn method, and the display offset position (from the passed cursor position in Set) can be set using the overloaded SetOffset method.

The class maintains a pointer to the active tip window ensuring that a single tip window is visible at a time.

Please bear in mind that it hasn't been designed for extending but does readily demonstrate the concepts behind getting it to work. If you wanted to change it so that you could use multi-line tips, then the Display and OnPaint methods can be changed to change the window size and display the text over the correct number of lines respectively. Please let me know if you find this class useful. If there is sufficient interest then I may update the class to enable it to be more easily extendable.

The class was developed and tested under Visual C++ v4.1 but should work equally well under VC5. (Note that with a few minor changes the class will work under VC1.5)

Download Files



Comments

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

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds