0

I'm trying to know if a WPF Window/Control is visible to the user (if it's hidden by other windows), and i found this function GetUpdateRect() but it only works with windows forms.

Is there any way to use the function GetUpdateRect() in WPF Controls/Windows? I tried everything and all i found is this:

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
internal struct RECT
{
    public int Left;
    public int Top;
    public int Right;
    public int Bottom;
    public int Width { get { return this.Right - this.Left; } }
    public int Height { get { return this.Bottom - this.Top; } }
}

[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern bool GetUpdateRect(IntPtr hWnd, ref RECT rect, bool bErase);

public static bool IsControlVisibleToUser(System.Windows.Forms.Control control)
{
    control.Invalidate();
    Rectangle bounds = control.Bounds;
    RECT rect = new RECT { Left = bounds.Left, Right = bounds.Right, Top = bounds.Top, Bottom = bounds.Bottom };
    return GetUpdateRect(control.Handle, ref rect, false);
}
Dan Homola
  • 3,819
  • 1
  • 28
  • 43
John Kilar
  • 65
  • 2
  • 11
  • possible duplicate of [What is the best way to determine if a window is actually visible in WPF](http://stackoverflow.com/questions/454792/what-is-the-best-way-to-determine-if-a-window-is-actually-visible-in-wpf) – JMK Aug 08 '13 at 15:37
  • are you looking for something like this? http://stackoverflow.com/questions/1517743/in-wpf-how-can-i-determine-whether-a-control-is-visible-to-the-user – devman Aug 08 '13 at 15:38
  • @bflosabre91 i've seen that post and it's not what i'm looking for, i want to know if window is visible, but your link post is talking about knowing if element is visible inside window – John Kilar Aug 08 '13 at 15:45

0 Answers0