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


  • What would exhort existence settle current to be more colorful of Studio

    Posted by motherdhmm on 06/04/2013 01:41pm

    [url=]beats by dre[/url] Starting with the to the fore complete, it is distinctly that the caricature agreeable does not shoulder the ¡°tm¡± (trademark) hieroglyph under the dope ¡°studio¡± on the bum radical management corner of the strike (may be a midget under age, but you can conjure up that a lilliputian second of reader is missing from the picture on the fitting). At the back of the slug, you can conscious of that the pictures of the headphones are slightly different. They are positioned slightly differently. Then there¡¯s also the scarcity of the ¡± tm ¡°sign beneath the¡± studio ¡°gen at the bottom left corner.¡± tm ¡°is also missing on the vertical verse on the radical of the crate underground the word¡± dre ¡°, and is also missing from the pattern hire of the model paragraph of text. [url=]beats studio[/url] Some people think that to travesty Jordan, Kobe Bryant, this is not pretend, but if the theory of the high-quality of their own accessories, and Bryant suffer with their own unique vision, which has a mammoth relationship and he was Europe¡¯s fashion cap Milan grew up, from slight monasteriesBryant has been wearing all kinds of form sunglasses, and every so often there is a negligible diamond stud earrings, there is a pompously ¡°Monster¡± regard cups in their culmination ¨C even the Monster headphones. he intent also own different colors, standard corpse-like, there are violet and gold with the Lakers. [url=]beats by dre headphones[/url] Eyesore iBeats Headphones with ControlTalk In-Ear Headphones ,has Advanced engineering reproduces high judgement sound from your iPhone or iPod for the treatment of a listening taste other buds are unequipped to deliver. Chic driver fashion pumps out the deepest bass, soaring highs, and ultra-clear midrange so you can end hearing the music and start listening to it. Lightweight for listening while exercising or when you¡¯re on the go. Sedulous chrome earphone finishes for hard durability and permanent shine. Precision-machined single-billet metal housing prevents vibrations and unwelcome sonic artifacts from tainting your listening experience.

  • ghd glattejern populære familie, som skal produktet

    Posted by motherdhmm on 05/30/2013 02:37pm

    [url=]beats by dre headphones[/url] Ligegyldigt hvilken slags hår fladjern du vil købe, hvordan det glatte hår er også meget vigtigt. Men du må hellere bruge bedre Billige GHD Glattejern for dit hår, bare for at holde dit hår er health.So, så tøv ikke mere, lige kommet til den officielle online butik for GHD glattejern. [url=]beats by dre nz[/url] vedrørende alle vigtige ingredienser inde i make-up middel som er som kan tage i de store uddannelse din energi og arbejde desuden [url=]monster beats australia[/url] Det har længe været bevist at ghd utvivlsomt er markedsledende med verdens bedste glattejern. Vi har hele sortimentet / udvalget af ghd glattejern til de bedste priser og her hos får du også leveret dit ghd glattejern direkte til døren helt og aldeles gratis.

  • thanks

    Posted by prasaath on 07/19/2012 03:49am

    Thanks for your class it helps more..........

  • is this your "without MFC"????

    Posted by jithinpg007 on 07/08/2008 07:45am

    hey dude, you hav captioned ur topics as tooltiptext without mfc and you hav all used the whole program in MFC only... toooooooooooo bad.......... plz specify how to set a tooltip text in pure VC++ not MFC

  • How all this can be done with the standard tooltip control

    Posted by Legacy on 04/20/2003 12:00am

    Originally posted by: Jose Insa

    All this can be done with the standard Tooltip ctrl, search in MSDN for article "Tiptoe Through the ToolTips", this article explains the use of tooltips very well.
    However, I still appreciate your contribution and respect everyone who shares their code or findings here. I don't understand people who make negative statements without helping in any way others...pointless

    • problem with compex data

      Posted by DieterHammer on 07/12/2005 04:02am

      The MSDN article is very fine, for my application it has only one problem. It needs a hittest for every MouseMove. If I have a very complex CAD document, this speeds down the mouse. I have to create my own event "Mouse doesn't move" and only then check hittest.

  • Simple Multiline Text

    Posted by Legacy on 08/17/2002 12:00am

    Originally posted by: Paul Shore

    The following changes in DisplayToolTip() will enable multiline tips.

    //original CSize size = pDC->GetTextExtent(m_szText);
    //original pDC->LPtoDP(&size);
    CRect lpRect; //new
    pDC->DrawText(m_szText, lpRect, // new
    CSize size(lpRect.Width(), lpRect.Height()); // new

    //original pDC->SetTextAlign(TA_LEFT);
    //original pDC->TextOut(3,1, m_szText);
    pDC->DrawText(m_szText, CRect(3,1,,, // new

    Call like this:

    m_ToolTip.SetText(_T("Some Tip Text\r\nOn Two Lines"));

  • Stop Bitching

    Posted by Legacy on 04/16/2002 12:00am

    Originally posted by: John Knight

    I often wonder why people bother contributing to this site when I see people moaning or trying to prove that they can do it better.

    Anyone who contributes to this site deserves respect. They have tried their best and are willing to share their ideas to HELP others.

    You don't have to use their code, you can draw lots of ideas from it.

    Give the programmers a break!

  • Optimisations

    Posted by Legacy on 03/01/2002 12:00am

    Originally posted by: Amn

    Thanks a lot for your help... i hate Windows, but i shall have to program a bit more for this platform... everything is damn upside down ... can't believe i have spent 4 hours fixing a tool tip control that is to be built from scratch, since the CToolTip wrapper can't do most of the things i need.. talk about extendability...

    Well, anyway your code saved me :)

    I know how to make it 2) smaller (no members :), and 2) faster (about 20 - 30%)

    here it goes:

    remove the CPaintDC dc(this) initialisation in OnPaint since you don't need it anyway (you perform all the drawing in the DisplayToolTip function).

    use the CS_OWNDC class style to have an exclusive device context (you won't need to release it, and the tool tips are so small Windows won't mind have an exclusive device context to your tooltips, and since there can be only one at a time, CS_OWNDC is perfect for the job.

    Thanks again for the code !


  • It's still MFC based !

    Posted by Legacy on 01/14/2002 12:00am

    Originally posted by: andy k.

    Think your title is wrong, if u use CWnd, and include stdafx.h, you carry all the MFC in your program. Searched a "pure Win32" ballon application? Your one isn't !

  • On subsequent mouse moves it does not update the tool tip

    Posted by Legacy on 11/14/2001 12:00am

    Originally posted by: Jaky

    The tool tip that is displayed only appears at the first point that the mousemove supplies. On subsequent mouse moves it does not update the tool tip, it does not disapear and just stays displayed at the first point.
    What modifications need to be made to make it be displayed under the cursor as it moves?

  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

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