.netPlus / Samples / VB | ||
Filename: | vbbubble.zip |
Last update: | 01/10/01 |
Size: | 15 kb |
Overview
The sample demonstrates how to add multiline and text alignment support to your
VB tooltips. It's done the hard way, by subclassing the tooltip window and handle
all the drawing. But the code is encapsulated in a BAS module that can be included
in any project, and used by simply adding two function calls. Users familiar
with the Windows API can customize the drawing routine to add extra effects.
The code only works on the tooltips provided by VB's Extender object and that is added to all contorls. It will not affect tooltips created internally by controls, such as the ListItem tips in a ListView control.
For an alternative way to create multiline tooltips, based on the control in Comctl32.dll, see the links below.
Details
A VB program will only have one single tooltip window per process. The window
has the classname "VBBubble" in the IDE, and "VBBubbleRT5" or "VBBubbleRT6"
during runtime, depending on VB version. The window is created the first time
the mouse cursor passes over the client area of a Form or UserControl (first
WM_MOUSEMOVE message).
While working in the IDE, the tooltip window will not be destroyed as you start and stop the application. The same window will be used until you quit VB.
This sample first uses the EnumThreadWindows function to try to locate an existing tooltip window. If that fails, it sets up a thread CBT hook using SetWindowsHookEx so the application gets notified when a window is created. In any case, when a tooltip window is found, it's subclassed. The module will then handle the WM_WINDOWPOSCHANGING and WM_PAINT messages so that the window is sized and drawn like we want it.
To enable this, call the HookToolTips function in the module. This is normally done sometime during application startup, in Form_Load or Sub Main. You also have to call the UnhookToolTips function before the application ends to remove the subclass. Not doing that might cause the application to crash when closed.
The module also has two property procedures, MaxTipWidth and HideToolTips. MaxTipWidth sets the maximum allowed width of the tooltip window, in pixels. If a line of text in the tooltip is wider than that, the text will be wrapped to the next line. The HideToolTips property will prevent all tooltips from showing when set to True, without having to clear all ToolTipText properties.
The text alignment feature is set by adding an "alignment tag" to the beginning of the tooltip text. "<c>" will center the text and "<r>" will align it to the right. The default when no tag is given is left aligned text.
See also
http://www.mvps.org/btmtz/tooltip/
http://www.mvps.org/btmtz/vbbubble/
©2000-2024, .netPlus