GetWindowRect returns odd values
<p>I hope that someone will be able to help me with this, I have the following bit of code in my application in a method to get me a Rect</p>

<pre><code>var windowPosition = NativeMethods.GetWindowRect(this._hwnd);
return new Rect(windowPosition.Left, windowPosition.Top, windowPosition.Width, windowPosition.Height);
</code></pre>

<p>I am using this in some code that I have written for a custom window and this is in a WPF application, the window is opened using the <code>IWindowManager.OpenWindow</code>.</p>

<p>When I run the code and open the window I am getting the following values in the <code>windowPosition</code> object which is a RECT</p>

<pre><code>top = 1466, bottom = 785, left = 26, right = 26, width = 0, height = -681
</code></pre>

<p>I cannot see what is wrong in the code that would end up with these odd values in the RECT, and I get an <code>ArgumentException</code> in the next line as a result.</p>

<p>I have also tried running this window as the main application window and I am getting the same problem, the application is using MVVM and Caliburn Micro although im not sure why that should make a difference.</p>

<p>As requested the RECT struct is defined as below:</p>

<pre><code>[StructLayout(LayoutKind.Sequential)]
internal struct RECT
{
    public void Offset(int dx, int dy)
    {
        this.Left += dx;
        this.Top += dy;
        this.Right += dx;
        this.Bottom += dy;
    }

    public int Left { get; set; }

    public int Top { get; set; }

    public int Right { get; set; }

    public int Bottom { get; set; }

    public int Width
    {
        get
        {
            return this.Right - this.Left;
        }
    }

    public int Height
    {
        get
        {
            return this.Bottom - this.Top;
        }
    }

    public POINT Position
    {
        get
        {
            return new POINT { x = this.Left, y = this.Top };
        }
    }

    public SIZE Size
    {
        get
        {
            return new SIZE { cx = this.Width, cy = this.Height };
        }
    }
}
</code></pre>

<p>and the GetWindowRect method from NativeMethods:</p>

<pre><code>    [DllImport("user32.dll", EntryPoint = "GetWindowRect", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool GetWindowRectInternal(IntPtr hWnd, out RECT lpRect);

    public static RECT GetWindowRect(IntPtr hwnd)
    {
        RECT rc;
        if (!GetWindowRectInternal(hwnd, out rc))
        {
            throw new Win32Exception(Marshal.GetLastWin32Error());
        }
        return rc;
    }
</code></pre>

<p>I am accessing <code>hWnd</code> using <code>WindowInteropHelper(window).Handle</code>, I neglected to include the public method from NativeMethods and have included that now, apologies for wasted time.</p>