December 24th, 2015

Why does my in-place tooltip dismiss itself as soon as it appears?

One subtlety in the use of in-place tooltips is that you should create the tooltip with the WS_EX_TRANSPARENT extended style.

This style makes the window invisible to hit-testing, which is a good thing here. The code that decides when to show and hide an in-place tooltip goes like this:

POINT ptCursor;
GetCursorPos();
HWND hwnd = WindowFromPoint(ptCursor);
if (hwnd == the_thing_that_needs_a_tooltip) {
 show_the_tooltip();
} else {
 hide_the_tooltip();
}

If the mouse enters the thing that needs a tooltip, then we show the tooltip. If the mouse leaves the thing that needs a tooltip, then we hide the tooltip.

Now let’s see what happens if you forget the extended style.

  • What window is the mouse currently over? → The item that needs an in-place tooltip.
  • Is that the thing that needs a tooltip? → Yes: Show the tooltip.
  • What window is the mouse currently over? → The tooltip window.
  • Is that the thing that needs a tooltip? → No: Hide the tooltip.
  • What window is the mouse currently over? → The item that needs an in-place tooltip.
  • Is that the thing that needs a tooltip? → Yes: Show the tooltip.
  • What window is the mouse currently over? → The tooltip window.
  • Is that the thing that needs a tooltip? → No: Hide the tooltip.

Oops, the tooltip keeps flashing in and out.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.