Click here to Skip to main content
6,292,426 members and growing! (9,739 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Tooltips     Intermediate License: The Code Project Open License (CPOL)

Multiline Titletips

By Chris Maunder, Mark Findlay

A class that allows you to display data for a control that is otherwise not large enough to display the full text
VC6, MFC, Dev
Posted:5 Jan 2000
Views:70,130
Bookmarked:47 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
32 votes for this article.
Popularity: 6.79 Rating: 4.51 out of 5

1

2
1 vote, 20.0%
3

4
4 votes, 80.0%
5
  • Download demo project - 23 Kb
  • Download source files - 5 Kb
  • Sample Image - Multiline_Titletips.gif

    A titletip is similar to a tooltip, but is used to display data in a control that is otherwise not large enough to display the full text. We are all used to seeing cell titletips that display contents that are hidden by the width of the cell. These titletips typically use a single line. If the contents are greater than the single line, they were truncated.

    The code presents a titletip class that can show the complete contents of a cell regardless of its size. The titletip window will adjust itself up or down depending on the cell being displayed, and will take into account the size of the parent's client area, and that of the screen. It will do its utmost to show you that data!

    This article is based on code written by Zafir Anjum, but has been extensively reworked to add a great deal of new functionality.

    How to use CTitleTip

    Using the class is extremely easy. Just declare an object of type CTitleTip in your main windows' header, and then create the title tip window in your dialog's OnInitDialog, or your view's OnInitialUpdate:

    // dialog header file
    
    class CTitleTipDemoDlg : public CDialog
    {
    	...
    	
    	CTitleTip m_TitleTip;
    }
    
    BOOL CTitleTipDemoDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    	...
    	m_TitleTip.Create(this);
    	
    	return TRUE;  // return TRUE  unless you set the focus to a control
    
    }
    

    You then need to add a mouse over handler so that when the mouse cursor moves over controls that may contain large amounts of text, you can popup a title tip to display that text. For instance, in our demo dialog we have a static control (m_staticText) that displays a lot of text. Just add an OnMouseMove handler and add the following code:

    void CTitleTipDemoDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    	// Get the dimensions of the static control
    
    	CRect rect;
    	m_staticText.GetWindowRect(rect);
    	ScreenToClient(rect);
    
    	// If the mouse is over the control, display the titletip. 
    
    	// Note: The title tip will only be displayed if the text
    
    	// in the static control is too large for the static control
    
    	if (rect.PtInRect(point))
    	{
    		CString str;
    		m_staticText.GetWindowText(str);
    		m_TitleTip.Show(rect, str, 0, 80);
    	}
    	
    	CDialog::OnMouseMove(nFlags, point);
    }

    The CTitleTip::Show function has the following syntax

    void Show(CRect rectTitle,            // Bounds of the control containing the text
    
              LPCTSTR lpszTitleText,      // The text to display
    
              int xoffset = 0,            // offset to display text within title tip
    
              int nMaxChars = -1,         // Maximum number of characters per line to display
    
              LPRECT lpHoverRect = NULL,  // Once the mouse moves outside of this
    
                                          //   rect, the title tip will disappear
    
              LPLOGFONT lpLogFont = NULL) // The font in which to display the text
    
    

    If nMaxChars is less than 0, then the text will only wrap where there is insufficient room to display the entire line.

    if lpHoverRect is NULL then it will be set as rectTitle.

    License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    About the Authors

    Chris Maunder


    Member
    Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

    His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

    He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

    Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
    Occupation: Founder
    Company: The Code Project
    Location: Canada Canada

    Mark Findlay


    Member

    Location: United States United States

    Other popular Miscellaneous articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 16 of 16 (Total in Forum: 16) (Refresh)FirstPrevNext
    GeneralGood Job Pinmemberclxye16:50 13 Dec '07  
    GeneralCTitleTip Class not found Pinmember123Asha21:40 4 Sep '07  
    GeneralTo display Custom tooltiptext in taskbar Pinmember123Asha21:37 4 Sep '07  
    GeneralCan this be used with app's taskbar button tooltip ??? Pinmemberana_v12314:01 11 Apr '06  
    GeneralStrage behaviour Pinmemberiasen_st4:01 23 Aug '04  
    Generalproblem! pls help! Pinmemberns8:53 12 Nov '03  
    GeneralTrying to use an edit box Pinmemberns5:22 7 Nov '03  
    Generalnice work...and bug? PinmemberHighJack22:52 11 Feb '03  
    GeneralExcellent PinmemberJohnJ1:41 3 Jan '03  
    GeneralHow can I use this titletip in CGridctrl. PinsussAnonymous19:32 3 Nov '02  
    GeneralRe: How can I use this titletip in CGridctrl. PinmemberChopper1:21 18 Dec '02  
    Generalnice work PinmemberKevin Smith10:44 26 Aug '02  
    GeneralSDI app PinsussKevin Smith9:52 23 Aug '02  
    GeneralCan't detect double click Pinmemberhierro4:17 30 Nov '01  
    GeneralRe: Can't detect double click PinmemberRoger Allen7:25 16 Apr '02  
    GeneralAn easier way... PinmemberR6:48 5 Aug '02  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 5 Jan 2000
    Editor: Chris Maunder
    Copyright 2000 by Chris Maunder, Mark Findlay
    Everything else Copyright © CodeProject, 1999-2009
    Web17 | Advertise on the Code Project