internal static void FindMonitorRectsFromPoint(System.Windows.Point point, out Rect monitorRect, out Rect workAreaRect)
 {
     var hMonitor = NativeMethods.NativeMethods.MonitorFromPoint(new Point
     {
         X = (int)point.X,
         Y = (int)point.Y
     }, 2);
     monitorRect = new Rect(0.0, 0.0, 0.0, 0.0);
     workAreaRect = new Rect(0.0, 0.0, 0.0, 0.0);
     if (!(hMonitor != IntPtr.Zero))
         return;
     var monitorInfo = new Monitorinfo {CbSize = (uint) Marshal.SizeOf(typeof (Monitorinfo))};
     NativeMethods.NativeMethods.GetMonitorInfo(hMonitor, ref monitorInfo);
     monitorRect = new Rect(monitorInfo.RcMonitor.Position, monitorInfo.RcMonitor.Size);
     workAreaRect = new Rect(monitorInfo.RcWork.Position, monitorInfo.RcWork.Size);
 }
 internal static void FindMaximumSingleMonitorRectangle(RECT windowRect, out RECT screenSubRect, out RECT monitorRect)
 {
     var rects = new List<RECT>();
     NativeMethods.NativeMethods.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, (IntPtr hMonitor, IntPtr hdcMonitor, ref RECT rect, IntPtr lpData) =>
     {
         Monitorinfo monitorInfo = new Monitorinfo {CbSize = (uint) Marshal.SizeOf(typeof (Monitorinfo))};
         NativeMethods.NativeMethods.GetMonitorInfo(hMonitor, ref monitorInfo);
         rects.Add(monitorInfo.RcWork);
         return true;
     }, IntPtr.Zero);
     var num1 = 0L;
     screenSubRect = new RECT()
     {
         Left = 0,
         Right = 0,
         Top = 0,
         Bottom = 0
     };
     monitorRect = new RECT()
     {
         Left = 0,
         Right = 0,
         Top = 0,
         Bottom = 0
     };
     foreach (RECT rect in rects)
     {
         var lprcSrc1 = rect;
         RECT lprcDst;
         NativeMethods.NativeMethods.IntersectRect(out lprcDst, ref lprcSrc1, ref windowRect);
         var num2 = (long)(lprcDst.Width * lprcDst.Height);
         if (num2 > num1)
         {
             screenSubRect = lprcDst;
             monitorRect = rect;
             num1 = num2;
         }
     }
 }
 private static Monitorinfo MonitorInfoFromWindow(IntPtr hWnd)
 {
     var hMonitor = NativeMethods.MonitorFromWindow(hWnd, 2);
     var monitorInfo = new Monitorinfo { CbSize = (uint)Marshal.SizeOf(typeof(Monitorinfo)) };
     NativeMethods.GetMonitorInfo(hMonitor, ref monitorInfo);
     return monitorInfo;
 }