'Best way to determine if a user can view a window
How can I determine if a user can see a window (fully or partially) at the screen using WPF/C#?
I tried to define this using WindowState, but the window may be “under” other windows.
For example now the window are focused and user can view it:
Now part of window are covered with IDE, but user still can view it:
Now the window is completely covered by the IDE window, and the user cannot see it.
How can I now determine in what "visible state" the window is?
Solution 1:[1]
You could do a "hit test" on the 4 corners coordinates and if all tests return your window then the window is completely visible.
- see also: VisualTreeHelper.HitTest function
- see also: WindowFromPoint function (user32.dll)
Solution 2:[2]
You can track when your application active(or focused) but I am not sure is it possible with a partially visible window, in any case, read this, hope it will be helpful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kux |
Solution 2 | STG |