Balloon Tooltips with the Tooltip Component

divil

Ultimate Contributor
Joined
Nov 17, 2002
Location
England
The Tooltip component is a great way of extending your controls to add tooltips to them. However, it has no inbuilt capability for displaying balloon-style tooltips so I knocked up this example.

A Tooltip is a special window maintained by the component you put on your form. Windows takes care of the positioning and resizing of the window to give it that familiar look, but the Tooltip component has to create and maintain that window. It keeps track of its window internally, and here's where the nasty part comes in.

I use reflection to get a hold of the native window the Tooltip component keeps in a private field. Once I have that, I can then access its hwnd, and from there change its window style. The style we need to remove is WS_BORDER, because when that is combined with balloon tooltips great ugliness ensues. The styles we need to make sure are applied are TTS_BALLOON and TTS_NOPREFIX.

After using GetWindowLong and SetWindowLong to accomplish this change to the window style, that's it. All tooltips displayed from then on are shown with a balloon.

I've attacked a zip file containing a simple project. The large button has a tooltip, and pressing the smaller button invokes our code that forces subsequent tooltips to be balloons.

[edit] Removed ghost reference - thanks Derek [/edit]
 

Attachments

  • balloon.zip
    8.3 KB · Views: 382
Last edited:
Top Bottom