|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionRecently, I wanted to show a tool-tip to display some information about an object in a diagram. I wanted the tool-tip to contain the name of the object, followed by any comment text about that object. That was fine, except it looked very plain. What I really wanted was to show the object's name in a bold font, and the rest in the normal font, so I came up with the control presented here. This control is a drop-in replacement for a Using the Demo ApplicationThe demo application demonstrates the rich-tip control using a simple edit control, whose text is added to its tool-tip, and also a rich-edit control, with a few formatting buttons. Text in the rich-edit control appears in the tip for the rich-edit control. Rich-text may be pasted into the rich-edit control from other applications, or alternatively, if there is a file named test.rtf in the EXE's directory, then it is streamed into the control on running the application. Using the ControlThis control should be used in exactly the same way as Add a CRichToolTipCtrl m_tip;
Next, add a call to create the control in your m_tip.Create(this);
You should then add the following line to your m_tip.RelayEvent(pMsg);
Once that's done, you can start adding tools to the control. So, to add a tool tip to the OK button of a dialog, you would then call, in your m_tip.AddTool(GetDlgItem(IDOK), _T("{\\rtf This is my {\\b OK} button}"));
As with the standard Implementation NotesOnce I had realised that I was going to write my own control, I had to come up with a way of entering text such that it could be parsed, and displayed. I had a choice:
I didn't really want to do 1 or 2, and I favoured RTF over HTML, as images can be embedded into RTF, so I had a look at the WordPad sources, which uses Having found out how to render the RTF, I added a handler for the This was fine except that the tool-tip window was sized to fit the original mark-up text, which is often very big, so it needed resizing. After some searching, I found the article Calculating a Rich Edit Control Minimum Size by Thales P. Carvalho, which allowed me to calculate the correct size for the tip window. I then re-positioned the window to a sensible place based on the cursor position. This was enough to display basic formatted text in a tip window, but I wanted to be able to support embedded images. To implement this in a rich edit control, it is necessary to give the control an OLE callback handler (a pointer to an DocumentationThe static CString MakeTextRTFSafe(LPCTSTR lpszText);
This Acknowledgements and References
HistoryVersion 1.2 - 06 Oct 2008
Version 1.1 - 22 Mar 2005
Version 1.0 - 14 Mar 2005
|
||||||||||||||||||||||