Ejemplo n.º 1
0
        private static Win32Api.W32Rect GetMonitor(Win32Api.W32Point position)
        {
            IntPtr monitorHandle = Win32Api.MonitorFromPoint(position, Win32Api.MonitorOptions.MONITOR_DEFAULT_NEAREST); //0x00000002: return nearest monitor if pt is not contained in any monitor

            Win32Api.W32MonitorInfo monitorInfo = new Win32Api.W32MonitorInfo
            {
                Size = Marshal.SizeOf(typeof(Win32Api.W32MonitorInfo))
            };

            if (!Win32Api.GetMonitorInfo(monitorHandle, ref monitorInfo))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }

            return(monitorInfo.WorkArea);
        }
Ejemplo n.º 2
0
        public static Win32Api.W32Rect GetPrimaryMonitor()
        {
            IntPtr monitorHandle = Win32Api.MonitorFromPoint(new Win32Api.W32Point()
            {
                X = 0, Y = 0
            }, Win32Api.MonitorOptions.MONITOR_DEFAULT_PRIMARY);

            Win32Api.W32MonitorInfo monitorInfo = new Win32Api.W32MonitorInfo
            {
                Size = Marshal.SizeOf(typeof(Win32Api.W32MonitorInfo))
            };

            if (!Win32Api.GetMonitorInfo(monitorHandle, ref monitorInfo))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }

            return(monitorInfo.WorkArea);
        }
Ejemplo n.º 3
0
        public static void Maximize(Window window, IntPtr hWnd)
        {
            IntPtr monitor = Win32Api.MonitorFromWindow(hWnd, Win32Api.MonitorOptions.MONITOR_DEFAULT_NEAREST);

            if (monitor == IntPtr.Zero)
            {
                return;
            }

            Win32Api.W32MonitorInfo monitorInfo = new Win32Api.W32MonitorInfo()
            {
                Size = Marshal.SizeOf(typeof(Win32Api.W32MonitorInfo))
            };

            Win32Api.GetMonitorInfo(monitor, ref monitorInfo);
            Win32Api.W32Rect rcWorkArea    = monitorInfo.WorkArea;
            Win32Api.W32Rect rcMonitorArea = monitorInfo.Monitor;
            window.Left   = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left);
            window.Top    = Math.Abs(rcWorkArea.Top - rcMonitorArea.Top);
            window.Width  = Math.Abs(rcWorkArea.Right - rcWorkArea.Left);
            window.Height = Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top);
        }