RTF-Based Tooltips
This code demonstrates using rich text in tooltips, as seen in Query Analyser utility of MS SQL Server 7.
It is more like a proof-of-concept then a finished code, and is heavily based on two classes from CodeGuru :
TFXDataTip by S. Wilson and CAutoRichEditCtrl by Jeremy Iverson
First class was modifyed to hold a hidden AutoRichEdit control as a static member and use it for rendering the
RTF text to the window. Function of AutoRichEdit are used to load text into the control.
Most of the magic behind the code is in the OnPaint handler of the tooltip window. The idea is to utilise RichEdit printing functions to copy the picture to screen DC instead of printer.
void TFXDataTip::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(&rect);
dc.SetBkColor(::GetSysColor(COLOR_INFOBK));
//dc.SetTextColor(::GetSysColor(COLOR_INFOTEXT));
//dc.SetMapMode(MM_TEXT);
if(_richCtrl)
{
_richCtrl->SetRTF(m_tip);
FORMATRANGE fr;
fr.hdc = dc;
fr.hdcTarget = dc;
fr.rc = CRect((rect.Width( ) / 2), (_border / 2) ,m_size.cx*15, m_size.cy*15);
fr.rcPage = CRect(0,0,0,0);
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
_richCtrl->FormatRange( &fr );
}
}
Using it from the dialog is also rather simple :
void CRich1Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd *pwnd = ChildWindowFromPoint(point);
if(pwnd)
{
int nID = pwnd->GetDlgCtrlID();
switch(nID)
{
case IDC_RICH_PLACEHOLDER:
m_datatip.Set(point, m_tip1);
break;
case IDC_TEXT:
m_datatip.Set(point, m_tip2);
break;
case IDC_IMAGE_PLACEHOLDER:
m_datatip.Set(point, m_tip3);
break;
default:
break;
}
}
CDialog::OnMouseMove(nFlags, point);
}
Issues and possible enhancements :

Comments
Picture Not Showing
Posted by Legacy on 01/23/2004 12:00amOriginally posted by: gush
why is the picture not showing in the tooltip?
ReplyHow to do this with a Html Edit Control?
Posted by Legacy on 12/20/2003 12:00amOriginally posted by: Appstmd
Hi!
Is it possible to do the same thing with the Microsoft Html Edit ActiveX Control?
What are the equivalent printing functions for this control?
Thks in advance.
ReplyHow to feed text to Richedit control
Posted by Legacy on 02/08/2003 12:00amOriginally posted by: Vikas
I have a string which has some rtf text to be printed. I have created a richedit control and then I feed the string to the control using WM_SETTEXT message. The problem that I am facing is that Richedit control only consumes the text worth of one paragraph instead of the whole text. How can I make this text consume the whole text?
ReplyI know why 15, but 15 is uncertain!
Posted by Legacy on 10/13/2001 12:00amOriginally posted by: Edwin Zhang
MSDN says very clearly that:
for rc and rcPage in FORMATRANGE, their unit should be measured in twips, and we all know 1 inch is 1440 twips,
so you can write as:
...
long lWidth = ::MulDiv(rect.Width(), 1440, dc.GetDeviceCaps(LOGPIXELSX));
long lHeight = ::MulDiv(rect.Height(), 1440, dc.GetDeviceCaps(LOGPIXELSY));
CRect rcPage(0, 0, lWidth, lHeight);
fr.rc = rcPage;
fr.rcPage = rcPage;
...
For dc.GetDeviceCaps(LOGPIXELSX) usually equals 96, so 1440 / 96 = 15. but you know you can not use 15 for safety reason.
ReplyRE: concerning the '15' constant
Posted by Legacy on 07/17/2001 12:00amOriginally posted by: JMB
concerning the '15' constant
...
I have no idea about your CRTfxxx project,
but 15 sounds to me as the VB TxipPerPixels? constants
(? being X or Y, in a std 'small fonts' environment)
Please refer to MSDN/VB docs for the definition of the TWIP as a device-independent[???] unit )
Maybe this might be a hint - no other ambition implied
Rgds
--JMB
ReplyAuto complete prompting
Posted by Legacy on 05/21/2001 12:00amOriginally posted by: Shrinivas
Hi,
I'm trying to do the Atocomplete prompting in my MDI application with CRichEditView.
Atocomplete prompting - In MS Word if you type Janu, a yellow tooltip kind of box pops up above the current caret position with word "January" in it and now if you hit Enter key half typed Janu gets replaced by word January.
I want to do the similar kind of functionality in my application for some selected words. Is it anything to do with the tool tips?
Any pointer to this is highly appreciated.
thanks,
ReplyShrini
Some little modifications
Posted by Legacy on 07/24/1999 12:00amOriginally posted by: FRED
ReplyRect coordinates in the FORMATRANGE struct
Posted by Legacy on 04/23/1999 12:00amOriginally posted by: Bartosz Bien
As VC6 MSDN library says, rectangles of rendering area and entire "page" area are in twips (which is 1/1440 of an inch). I'm not sure if the '15' is universal for all devices/devmodes.
Reply