Using Tooltips In Dialogs

Date: 12 September 1997
Author: Mark Caroli, University of Mannheim, Germany

Overview

The Tooltip control was introduced with the release of Windows95. This control displays a little hint text explaining the rough semantics of a control when the mouse cursor rests on the control for a while. This article solves the question "How to display tooltips in modal dialogs ? ". First, we focus on the procedure for normal windows. Analyzing the differences between conventional windows and modal dialog boxes raises the basic idea for the solution. A download sample is available.

Using Tooltips In A Normal Window

This section explains the use of tooltips in a conventional window. You have to add a TTooltip attribute to your Window class. In the window's constructor the tooltip instance is created. You only need the this pointer of the window.

The TWindow::SetupWindow() has to be overwritten for adding tools to the tooltip and activating it. Consult your BWCC online help for the various constructors of the TToolInfo class. In the code snippet below the parent window's handle, the handle of the receiving control and the hint text are passed to the constructor.

Finally, an overloaded version of the TWindow::PreProceesMsg(...) function containing a call to the TTooltip::RelayEvent() method leads to the desired result. Through this call the tooltip control knows when to display a tooltip for some control.


Deducing A Solution For Dialogs

The procedure described above can also be applied to modeless dialogs and to dialogs serving as the application's main window. If you call a dialog via the TDialog::Execute() method nothing will happen because modal dialogs suspend the application's message loop and therefore do not call PreProcessMsg(...). The tooltip control never gets to know when it is supposed ti display itself. The idea is to create a dialog which is modeless but simulates a modal dialog. This behaviour can be implemented by using TApplications' BeginModal(...) and End Modal(...) members. How this is done explicitly, can be seen in Borland's TI3163 (Attention: does not work in derived classes) or from the class TDialogBase which is included in the sample delivered with this article. Now the PreProcessMsg(...) method is called and the technique as described in the previous section is applicabable.

Further Resources