private RECT _GetAdjustedWindowRect(RECT rcWindow)
        {
            // This should only be used to work around issues in the Framework that were fixed in 4.0
            Assert.IsTrue(Utility.IsPresentationFrameworkVersionLessThan4);

            var style = (WS)NativeMethods.GetWindowLongPtr(_hwnd, GWL.STYLE);
            var exstyle = (WS_EX)NativeMethods.GetWindowLongPtr(_hwnd, GWL.EXSTYLE);

            return NativeMethods.AdjustWindowRectEx(rcWindow, style, false, exstyle);
        }
 private static extern bool _GetWindowRect(IntPtr hWnd, out RECT lpRect);
 private static extern bool _AdjustWindowRectEx(ref RECT lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle);
 public static IntPtr CreateRectRgnIndirect(RECT lprc)
 {
     IntPtr ret = _CreateRectRgnIndirect(ref lprc);
     if (IntPtr.Zero == ret)
     {
         throw new Win32Exception();
     }
     return ret;
 }
        public static RECT AdjustWindowRectEx(RECT lpRect, WS dwStyle, bool bMenu, WS_EX dwExStyle)
        {
            // Native version modifies the parameter in place.
            if (!_AdjustWindowRectEx(ref lpRect, dwStyle, bMenu, dwExStyle))
            {
                HRESULT.ThrowLastError();
            }

            return lpRect;
        }
 public static RECT Union(RECT rect1, RECT rect2)
 {
     return new RECT
     {
         Left = Math.Min(rect1.Left, rect2.Left),
         Top = Math.Min(rect1.Top, rect2.Top),
         Right = Math.Max(rect1.Right, rect2.Right),
         Bottom = Math.Max(rect1.Bottom, rect2.Bottom),
     };
 }