internal static NativeHelper.MONITORINFO GetMonitorInfo(IntPtr hWnd) { var monitor = NativeHelper.MonitorFromWindow(hWnd, NativeHelper.MONITOR_DEFAULTTONEAREST); if (monitor != IntPtr.Zero) { var monitorInfo = new NativeHelper.MONITORINFO(); NativeHelper.GetMonitorInfo(monitor, monitorInfo); return(monitorInfo); } return(null); }
internal static NativeHelper.MONITORINFO GetMonitorInfo(IntPtr hWnd) { var monitor = NativeHelper.MonitorFromWindow(hWnd, NativeHelper.MONITOR_DEFAULTTONEAREST); if (monitor != IntPtr.Zero) { var monitorInfo = new NativeHelper.MONITORINFO(); NativeHelper.GetMonitorInfo(monitor, monitorInfo); return monitorInfo; } return null; }
private static IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled) { switch (msg) { /* WM_GETMINMAXINFO */ case 0x0024: var mmi = (NativeHelper.MINMAXINFO)Marshal.PtrToStructure(lparam, typeof(NativeHelper.MINMAXINFO)); var monitor = NativeHelper.MonitorFromWindow(hwnd, NativeHelper.MONITOR_DEFAULTTONEAREST); if (monitor != IntPtr.Zero) { var monitorInfo = new NativeHelper.MONITORINFO(); NativeHelper.GetMonitorInfo(monitor, monitorInfo); NativeHelper.RECT rcWorkArea = monitorInfo.rcWork; NativeHelper.RECT rcMonitorArea = monitorInfo.rcMonitor; mmi.ptMaxPosition.X = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left); mmi.ptMaxPosition.Y = Math.Abs(rcWorkArea.Top - rcMonitorArea.Top); mmi.ptMaxSize.X = Math.Abs(rcWorkArea.Right - rcWorkArea.Left); mmi.ptMaxSize.Y = Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top); } Marshal.StructureToPtr(mmi, lparam, true); handled = true; break; } return IntPtr.Zero; }