Download demo project - 23 Kb
Download source files - 5 Kb

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:
class CTitleTipDemoDlg : public CDialog
{
...
CTitleTip m_TitleTip;
}
BOOL CTitleTipDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
...
m_TitleTip.Create(this);
return TRUE;
}
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)
{
CRect rect;
m_staticText.GetWindowRect(rect);
ScreenToClient(rect);
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,
LPCTSTR lpszTitleText,
int xoffset = 0,
int nMaxChars = -1,
LPRECT lpHoverRect = NULL,
LPLOGFONT lpLogFont = NULL)
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.
|
|
 |
 | Good Job clxye | 16:50 13 Dec '07 |
|
 |
Thank you!
|
|
|
|
 |
 | CTitleTip Class not found 123Asha | 21:40 4 Sep '07 |
|
 |
When i use the above mentioned CTitleTip class, it is said tht
CTitleTip' : missing storage-class or type specifiers
|
|
|
|
 |
 | To display Custom tooltiptext in taskbar 123Asha | 21:37 4 Sep '07 |
|
 |
i need to display a tooltip text in a taskbar for an application other than appication's window text...
can anyone help me for that
|
|
|
|
 |
 | Can this be used with app's taskbar button tooltip ??? ana_v123 | 14:01 11 Apr '06 |
|
 |
How to use this control be used to replace app's taskbar button tooltip ???
For MDI Application (MFC/VC++6.0), when we place mouse cursor over taskbar button of that application, ToolTip is displayed (showing application Title). How to modify toolTip text and font (For one MDI Application and not system-wide) ?
Thanks for any idea or direction. Ana
Ana_v123
Ana_v123
|
|
|
|
 |
 | Strage behaviour iasen_st | 4:01 23 Aug '04 |
|
 |
try this: move the object wih the titletip to the left or the right side ot the screen. and then do what you do to show the titletip.If it's the right side, then you'll notice that the titletip is shown somewhere out of the screen If you choose the left side, the size is goin' crazy. Any ideas how to correct this?
Great work though.
|
|
|
|
 |
 | problem! pls help! ns | 8:53 12 Nov '03 |
|
 |
If I dblclick in the editbox thats currently showing the tooltip in the are not occupied by the tooltip, it freezes even when we go away from that area. How shall I get this to fix itself? Thanks, ns
|
|
|
|
 |
 | Trying to use an edit box ns | 5:22 7 Nov '03 |
|
 |
If I add another static t ext to your sample code, it works great. But if I put an edit control, it doesnt show the tooltip (the edit ctrl I mean) Help! Thanks, ns
|
|
|
|
 |
 | nice work...and bug? HighJack | 22:52 11 Feb '03 |
|
 |
TitleTip.cpp line:148 [CTitleTip::Show(...)] m_rectDisplay.right = m_rectDisplay.left + size.cx /*+ xoffset*/; Probably, "xoffset" is unnecessary.
TitleTip.cpp line:283 [CTitleTip::Show(...)] int nHeight = dc.DrawText(m_strTitle,&rectCalc,0 .... Before this, SelectObject(&Font) is required.
if (lpLogFont) pOldFont = dc.SelectObject( &font ); else pOldFont = dc.SelectObject( m_pParentWnd->GetFont() ); int nHeight = dc.DrawText(m_strTitle,&rectCalc,0 | DT_CALCRECT | DT_LEFT | DT_NOCLIP | DT_EDITCONTROL | DT_NOPREFIX | DT_WORDBREAK ); pOldFont = dc.SelectObject( pOldFont );
Thanks Chris
|
|
|
|
 |
 | Excellent JohnJ | 1:41 3 Jan '03 |
|
 |
Very good - I was fiddling around trying to get a multiline tooltip to work on Tree control items - Problem solved!!
Thanks Chris
JohnJ
Sleep(28800000); http://www.rainbow-innov.co.uk[^]
|
|
|
|
 |
 | How can I use this titletip in CGridctrl. Anonymous | 19:32 3 Nov '02 |
|
 |
How can I use this titletip in CGridctrl. Please Help..
|
|
|
|
 |
|
 |
hi, a bit off-topic, but since you got no answer here i could an answer by suggesting to visit www.tooltips.net where you can download tooltips attachable to anything.
Regards, Vitaly Tomilov
|
|
|
|
 |
 | nice work Kevin Smith | 10:44 26 Aug '02 |
|
 |
excellent! and cool, I got this working
|
|
|
|
 |
 | SDI app Kevin Smith | 9:52 23 Aug '02 |
|
 |
How can I use this so a tooltip appears when my mouse is over a column heading in my CListView? Sample code would be appreciated.
Thanks
|
|
|
|
 |
 | Can't detect double click hierro | 4:17 30 Nov '01 |
|
 |
I used your multiline titletip, works great. But after using it, the CRect object can't detect any double click messages. Instead it'll invoke the LButtonDown function which is in place also. Any idea how to circumvent that?
|
|
|
|
 |
|
 |
You can handle the double click like this in the OnLButtonDown()
static bool double_wait = false ; static bool handled = false ; MSG msg ; if (double_wait) { TRACE("Double click\n") ; handled = true ; return ; } else
handled = false ; double_wait = true ; UINT time = GetDoubleClickTime() ; UINT slice = time / 10 ; for (int i = 0 ; i < 10 && !handled ; i++) { if (i == 9) Sleep(slice + time % 10) ; else
Sleep(slice) ; while (::PeekMessage(&msg, NULL, 0, 0, PM_NOYIELD | PM_REMOVE)) { ::TranslateMessage(&msg) ; ::DispatchMessage(&msg) ; } } if (!handled) { TRACE("Single click\n") ; } double_wait = false ;
Roger Allen Sonork 100.10016
yet to be identified being from the planet Paltinmoriumbanfrettybooter
|
|
|
|
 |
|
 |
There is an easier way...
1. Add CS_DBLCLKS to the WNDCLASS style so that the TitleTip receives double-click messages:
In CTitleTip::CTitletip()
wndcls.style = CS_SAVEBITS;
changes to:
wndcls.style = CS_SAVEBITS | CS_DBLCLKS;
2. Add WM_LBUTTONDBLCLK to the messages recognised by the PreTranslateMessage:
In CTitleTip::PreTranslateMessage(MSG* pMsg)
switch (pMsg->message) { case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN:
changes to:
switch (pMsg->message) { case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_LBUTTONDBLCLK:
and
switch (pMsg->message) { case WM_LBUTTONDOWN: pMsg->message = WM_NCLBUTTONDOWN; break; case WM_RBUTTONDOWN: pMsg->message = WM_NCRBUTTONDOWN; break; case WM_MBUTTONDOWN: pMsg->message = WM_NCMBUTTONDOWN; break; }
changes to:
switch (pMsg->message) { case WM_LBUTTONDOWN: pMsg->message = WM_NCLBUTTONDOWN; break; case WM_RBUTTONDOWN: pMsg->message = WM_NCRBUTTONDOWN; break; case WM_MBUTTONDOWN: pMsg->message = WM_NCMBUTTONDOWN; break; case WM_LBUTTONDBLCLK: pMsg->message = WM_NCLBUTTONDBLCLK; }
3. Handle the WM_LBUTTONDBLCLK message as normal in the titletip's parent.
Doing it this way keeps it nice and neat, and handles the double-click in the same way as the single click. I believe this method will also work for other messages (e.g. Keydown's).
|
|
|
|
 |
|
|
Last Updated 6 Jan 2000 |
Advertise |
Privacy |
Terms of Use |
Copyright ©
CodeProject, 1999-2010