Let's say you using a ctrl that support item data (CTreeView for
and you wish to add tool tip support , well,you can find some good articles
explaining you exactly what to do ( look in the treeview section in code guru,
Zafir Anjum's article will give you all the information you need. But,
if you want to display a custom tool tip for each item? One which is not based
only on the item text? Well, I've searched for a class which will
give me the freedom to display any tool tip I want and couldn't find any .
The following method will allow you to display an item tool tip ,which you
will be composed according to the item data , so you can ,for example show a
tool tip with a phone number when your mouse is over a name in a list ctrl .
The methods will be shown through the use of a
derived class , but
can be used with other controllers that support set\get item data. This article will not focus on the technical sides of adding tool tip support
to your controller.
I would like to thank Yaniv ben ari
for his great idea .
What is this Class ?
CTreeCtrlCh is a
derived class , which display tool tip according
to the item data You can attach any string you like to the any tree item using
SetItemData function , and this text will be displayed as tool tip
How does this class work?
This class uses an abstract class as an
templete. The user must
derived it's own
class from the abstract class ,and must implement a
virtual function called:
GetToolTipString , this function returns a
object which will be displayed as tool tip . the user should construct this
object according to his Own
class. sounds a little
complicated ? it's not...follow me to next section
How To Use This Class?
- Add the files you've downloaded to your project directory and add them to
- Add a TreeCtrl to your dialog, and assign him a member using the
- Add the following statment to your dialog header file:
- Change the tree control variable type to
- In the dialog header file construct a new class derived from
ItemDataABSTRACT as public. This class will be uses as your tree item data
, add any data member you want. Also add the function
to that class.
class TTipItemData:public ItemDataABSTRACT
- in your dialog implementation file ,you need to implement the
GetToolTipString() function This function MUST return a CString object, this
object will be displayed as the item tool tip In this function you can
manipulate the item data members and construct any string you want like
additional information on the item, dates, size and etc .
strTool = "";
pos = NULL;
- when you to add item data , declare a pointer to the class you've derived from ItemDataABSTRACT assign data to it's member,
TTipItemData* p ;
p = new TTipItemData;
p->strTool = "is ran";
- There is no need to delete the memory allocated, the CTreeCtrlch will
free all allocated memory used for item data