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

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon