April 5th, 2007

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

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.

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.