internal Screen(IntPtr monitor, IntPtr hdc) { IntPtr screenDC = hdc; if (!multiMonitorSupport || monitor == (IntPtr)PRIMARY_MONITOR) { // Single monitor system // bounds = SystemInformation.VirtualScreen; workingArea = SystemInformation.WorkingArea; 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. // NativeMethods.MONITORINFOEX info = new NativeMethods.MONITORINFOEX(); SafeNativeMethods.GetMonitorInfo(new HandleRef(null, monitor), info); bounds = Rectangle.FromLTRB(info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right, info.rcMonitor.bottom); workingArea = Rectangle.FromLTRB(info.rcWork.left, info.rcWork.top, info.rcWork.right, info.rcWork.bottom); primary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0); int count = info.szDevice.Length; while (count > 0 && info.szDevice[count - 1] == (char)0) { count--; } deviceName = new string(info.szDevice); deviceName = deviceName.TrimEnd((char)0); if (hdc == IntPtr.Zero) { screenDC = UnsafeNativeMethods.CreateDC(deviceName); } } hmonitor = monitor; this.bitDepth = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.BITSPIXEL); this.bitDepth *= UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.PLANES); if (hdc != screenDC) { UnsafeNativeMethods.DeleteDC(new HandleRef(null, screenDC)); } }
internal static WindowsGraphics GetMeasurementsGraphicsForHandleRef(HandleRef hWndHandleRef) { IntPtr monitor = SafeNativeMethods.MonitorFromWindow(hWndHandleRef, MONITOR_DEFAULTTONEAREST); NativeMethods.MONITORINFOEX info = new NativeMethods.MONITORINFOEX(); if (SafeNativeMethods.GetMonitorInfo(new HandleRef(null, monitor), info)) { string deviceName = new string(info.szDevice); deviceName = deviceName.TrimEnd((char)0); foreach (Screen s in Screen.AllScreens) { if (string.Compare(deviceName, s.DeviceName, StringComparison.InvariantCulture) == 0) { return(s.measurementGraphics); } } } return(null); }
internal Screen(IntPtr monitor, IntPtr hdc) { IntPtr screenDC = hdc; if (!multiMonitorSupport || monitor == (IntPtr)PRIMARY_MONITOR) { // Single monitor system // bounds = SystemInformation.VirtualScreen; primary = true; deviceName = "DISPLAY"; } else { // Multiple monitor system var info = new NativeMethods.MONITORINFOEX(); SafeNativeMethods.GetMonitorInfo(new HandleRef(null, monitor), info); bounds = Rectangle.FromLTRB(info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right, info.rcMonitor.bottom); primary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0); deviceName = new string(info.szDevice); deviceName = deviceName.TrimEnd((char)0); if (hdc == IntPtr.Zero) { screenDC = UnsafeNativeMethods.CreateDC(deviceName); } } hmonitor = monitor; this.bitDepth = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.BITSPIXEL); this.bitDepth *= UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.PLANES); if (hdc != screenDC) { UnsafeNativeMethods.DeleteDC(new HandleRef(null, screenDC)); } }