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.

Comments (8)
  1. GSerg says:

    So this is why in the SQL Management Studio that tooltip flashes like mad.

    In the query execution plan window, there might be a “missing index” hint in green, the details of which are shown in a huge tooltip if one hovers the mouse over the hint. However the tooltip is impossible to read because it flashes like mad.

    I wish the SQL Management Studio guys come across this post one day.

    1. Tim says:

      SSMS really needs a makeover. It’s still pretty buggy, it’s huge and takes forever to start up, most of the dialogs are completely broken in high DPI, and many common operations take an unnecessarily long time (like seeing which columns are contained in an index).

  2. Joshua says:

    Our solution was to create the tooltip 16px to the right. Also keeps the mouse cursor from overlapping it.

  3. Daniel M says:

    Your new blog design looks bad. I really miss the old design :-(

    1. JanH says:

      If you’re using a browser that supports user styles, try this one: https://userstyles.org/styles/121616/the-old-new-thing-classic-style
      Merry Christmas!

    2. M. Richards says:

      So, until now you’ve been reading Raymond’s blog for the aesthetics? :-)

      1. EMB says:

        aesthetics aaaannnnd HTML formated windows|dialogs. :P

  4. AsmGuru62 says:

    Windows sends WM_MOUSEMOVE when cursor X,Y remain the same, just window handle containing cursor is changed.
    This is what happens here too, tooltip is hidden (cursor is not moved) and Windows sends WM_MOUSEMOVE to
    the window beneath and cycle repeats. When HWND containing cursor is changed – only WM_SETCURSOR should be sent, but
    in addition WM_MOUSEMOVE also sent. Not cool!

Comments are closed.

Skip to main content