How can I prevent my own tooltip code from being drawn when that part of my window is closed by the window always on top?

We have implemented some custom code to draw the tooltips that fires Tick

timer events . Whenever this event fires, we check that our control is visible ( this.Visible

) and that it is the foreground window ( GetForegroundWindow()

).

The problem we are facing involves "always on top" windows such as the "Task Manager" or "Process Explorer" (when the "always on top" option is enabled). Since these windows are always on top, sometimes our application is closed / closed by such windows, but our tooltip pops up and draws over the top window.

I tried using the property Form.TopMost

, but that is not acceptable because then the tooltips never appear if there is an "always on top" window. In this case, our application is even active, so we have to show tooltips.

How do I detect / determine if there is an "always on top" window covering the area in my form where the mouse is hovering? I want the tooltip not to show "through" the window.

+2


source to share


1 answer


It looks like you are looking at the mouse position with a timer and then showing the tooltip. This is the wrong way. What you need to do is detect mouse movement messages. If you receive mouse move events telling you that the mouse is in a specific region, set a timer, and if the mouse hasn't left that area by the time the timer starts, display a tooltip. (By the way, how the native Windows tooltips work, see TrackMouseEvent

.)

This automatically solves your problem with always-on-top windows, because if a portion of the window is always closed on the top window, your form simply won't receive mouse move events for that region, so you don't need to check if the mouse is valid.



If you are using your current technique, you can use the API function WindowFromPoint

to determine which window is visible at any point on the screen. Use this to determine if your window is at the top where you plan to display the tooltip. ( The Net Framework API Map says the .Net equivalent is equivalent to this API function Form.GetChildAtPoint

, but that only gives the children of the .Net form, whereas you need to consider all top-level windows, including non-net windows.)

+3


source







All Articles