static bool MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, ref Rect lprcMonitor, IntPtr dwData) { List<Monitor> monitors=(List<Monitor>)GCHandle.FromIntPtr(dwData).Target; monitors.Add(new Monitor(hMonitor, hdcMonitor, lprcMonitor)); //MonitorInfo mi=new MonitorInfo(); //mi.cbSize=(uint)Marshal.SizeOf(mi); //GetMonitorInfo(hMonitor, ref mi); return true; }
/// <summary> /// Returns a list of all monitors (including invisible pseudo-monitors). /// </summary> /// <param name="hdc">The handle to a display device context that defines the visible region of interest.</param> /// <param name="rect">The region of interest as rectangle in virtual-screen coordinates if <paramref name="hdc"/> is <b>null</b>, otherwise in coordinates relative the the device context.</param> /// <returns>A list of all monitors.</returns> public static List<Monitor> GetDisplayMonitors(HDC hdc, Rect rect) { List<Monitor> monitors=new List<Monitor>(); GCHandle data=GCHandle.Alloc(monitors); try { EnumDisplayMonitors(hdc, ref rect, MonitorEnumProc, GCHandle.ToIntPtr(data)); } finally { data.Free(); } return monitors; }
/// <summary> /// Initializes the class. /// </summary> /// <param name="hMonitor">Handle to the display monitor.</param> /// <param name="hdcMonitor">Handle to device context.</param> /// <param name="lprcMonitor">Rectangle with the intersection of the clipping area of the device context and the display monitor rectangle.</param> public Monitor(HMONITOR hMonitor, HDC hdcMonitor, Rect lprcMonitor) { this.hMonitor=hMonitor; this.hdcMonitor=hdcMonitor; this.lprcMonitor=lprcMonitor; }
/// <summary> /// Returns a list of all monitors (including invisible pseudo-monitors). /// </summary> /// <param name="rect">The region of interest as rectangle in virtual-screen coordinates.</param> /// <returns>A list of all monitors.</returns> public static List<Monitor> GetDisplayMonitors(Rect rect) { return GetDisplayMonitors(HDC.Zero, rect); }