List Box with ToolTips






3.56/5 (5 votes)
Feb 21, 2001

129035

2905
A listbox that displays tooltips for items
Introduction
This tooltip enabled class lets the user display tooltip text for individual items. This class uses the tooltip class that is written by Dhandapani Ammasai.
A multiline tooltip for an individual item is automatically displayed towards the right of the control and the text is updated as the mouse is moved over the individual items in the list box.
Follow these steps to add a CTTListBox
to a dialog:
- Add TTListBox.cpp and TTListBox.h to your project.
- Add tooltip2.cpp and tooltip2.h to your project.
- Add
include "TTListBox.h"
to the header file of your dialog class. - Add a list box control to your dialog.
- Use ClassWizard to add a member variable of type
CTTListBox
for the list box you just added. IfCTTListBox
is not in the Variable Type list, chooseCListBox
, and manually change the type toCTTListBox
later. - In your dialog class, define a static member function which retrieves the
the text for individual items. This function must be declared as:
static CString TextRetriever(int nIndex);
where nIndex is the index of the list box item that currently is under the mouse cursor and wants to have the text retrieved.
- Implement the text retriever function the way you want it.
- In your dialog's class OnInitDialog function include a statment like:
m_listbox.SetTextRetrieverFcn(TextRetriever);
where TextRetriever is the name of your text retriever function that you declared earlier.
I have also implemented the same functionality for a tree control. You can e-mail me if you wish to look at how I implemented it for a tree control.