0

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:

Fully visible window


Now part of window are covered with IDE, but user still can view it:

Partially visible window


Now the window is completely covered by the IDE window, and the user cannot see it.

No visible window


How can I now determine in what "visible state" the window is?

qdot
  • 6,195
  • 5
  • 44
  • 95
SKProCH
  • 191
  • 1
  • 9
  • Does this answer your question? [How can I check that a window is fully visible on the user's screen?](https://stackoverflow.com/questions/6591090/how-can-i-check-that-a-window-is-fully-visible-on-the-users-screen) – Joehl Feb 07 '20 at 09:02
  • 2
    @Joehl i dont think this would solve the question at all. OP asks how to determinate whenever a certain window in WPF is rendered on top of all other windows so it is "seen" by the user. You link just reports if the window is "inside" any screen. – Venson Feb 07 '20 at 09:04
  • @SKProCh please edit your question, i don`t think the flag was appropriate and your question is a really interesting one. – Venson Feb 07 '20 at 09:08
  • I edited the question, but someone nevertheless continues to put him a minus. Maybe these users will also write in the comment, what is the reason for the minus and how to fix / avoid it? – SKProCH Feb 07 '20 at 11:48
  • See if this helps: https://stackoverflow.com/questions/825595/how-to-get-the-z-order-in-windows – auburg Feb 07 '20 at 17:02
  • what is the reason behind this why you u want to know this ? –  Feb 10 '20 at 10:42
  • @ketan I have a highly loaded event log, each update of which takes up computer resources. It is necessary if the user does not see the application not to update this, but to "store" events in the buffer – SKProCH Feb 10 '20 at 16:38

2 Answers2

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)
Kux
  • 1,362
  • 1
  • 16
  • 31
0

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.

STG
  • 93
  • 5