Why can't I display a tooltip for a disabled window?

Raymond Chen


Here’s a question that floated past my field of view some time ago:

When the mouse hovers over a disabled window, the tooltip associated with that window does not appear. Why is this? Why isn’t this documented in MSDN?

Actually, you already know the answer, and it is documented. You just have to connect the dots. When a window is disabled, it does not receive keyboard or mouse input. The documentation for EnableWindow says so in so many words, right in the first sentence. Next, how do tooltips know when to appear and disappear? Well, one way is to modify your window procedure so it takes all its input messages and forwards them to the tooltip control via the TTM_RELAYEVENT message. That way, the tooltip control knows where the mouse is and can show and hide itself accordingly. Alternatively, you can use the TTF_SUBCLASS flag to tell the tooltip control to subclass the tool window and grab the input itself. Both of these methods are also documented. Now put this all together. The tooltip control peeks at all the input destined for the tool window, either automatically via TTF_SUBCLASS or manually with TTM_RELAYEVENT. If the window is disabled, then it receives no input. Consequently, the tooltip control has no input to peek at and therefore doesn’t know when to appear or disappear. This is also why you don’t get tooltips for hidden windows and why you don’t get tooltips when the mouse is captured to another window.

So you see, you knew the answer all along. You just didn’t realize it.


Comments are closed.