public static Rectangle ScreenBoundsFromPoint(Point point) { var pt = new User32.POINT() { X = point.X, Y = point.Y }; var info = new User32.MonitorInfoEx();//new User32.MONITORINFOEX(); info.Init(); User32.GetMonitorInfo(User32.MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST), ref info); return(Rectangle.FromLTRB(info.Monitor.Left, info.Monitor.Top, info.Monitor.Right, info.Monitor.Bottom)); }
internal Screen(IntPtr monitor, IntPtr hdc) { currentDesktopChangedCount = -1; workingArea = Rectangle.Empty; IntPtr screenDC = hdc; if (!multiMonitorSupport || monitor == (IntPtr)PRIMARY_MONITOR) { // Single monitor system // if (User32.GetSystemMetrics(80) != 0) { bounds = new Rectangle(User32.GetSystemMetrics(76), User32.GetSystemMetrics(77), User32.GetSystemMetrics(78), User32.GetSystemMetrics(79)); } else { Size size = new Size(User32.GetSystemMetrics(0), User32.GetSystemMetrics(1)); bounds = new Rectangle(0, 0, size.Width, size.Height); } //bounds = SystemInformation.VirtualScreen; primary = true; deviceName = "DISPLAY"; } else { // MultiMonitor System // We call the 'A' version of GetMonitorInfoA() because // the 'W' version just never fills out the struct properly on Win2K. // var info = new User32.MonitorInfoEx(); info.Init(); User32.GetMonitorInfo(monitor, ref info); bounds = Rectangle.FromLTRB(info.Monitor.Left, info.Monitor.Top, info.Monitor.Right, info.Monitor.Bottom); primary = ((info.Flags & MONITORINFOF_PRIMARY) != 0); /*int count = info.DeviceName.Length; * while (count > 0 && info.DeviceName[count - 1] == (char)0) { * count--; * } * * deviceName = new string(info.szDevice); * deviceName = deviceName.TrimEnd((char)0);*/ deviceName = info.DeviceName; if (hdc == IntPtr.Zero) { screenDC = GDI32.CreateDC(deviceName, null, null, new HandleRef()); } } hmonitor = monitor; this.bitDepth = GDI32.GetDeviceCaps(new HandleRef(null, screenDC).Handle, 12); this.bitDepth *= GDI32.GetDeviceCaps(new HandleRef(null, screenDC).Handle, 14); if (hdc != screenDC) { GDI32.DeleteDC(new HandleRef(null, screenDC).Handle); } }