Ejemplo n.º 1
0
        /// <summary>
        /// From http://www.pinvoke.net/default.aspx/user32/EnumDisplayMonitors.html
        /// Returns the information about Displays using the Win32 functions
        /// </summary>
        /// <returns>collection of Display Info</returns>
        public static List <Win32Types.DisplayInfo> GetDisplays()
        {
            List <Win32Types.DisplayInfo> displayList = new List <Win32Types.DisplayInfo>();

            Win32Funcs.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
                                           delegate(IntPtr hMonitor, IntPtr hdcMonitor, ref Win32Types.RECT lprcMonitor, IntPtr dwData)
            {
                Win32Types.MonitorInfo mi = new Win32Types.MonitorInfo();
                mi.cbSize    = Marshal.SizeOf(mi);
                bool success = Win32Funcs.GetMonitorInfo(hMonitor, ref mi);
                if (success)
                {
                    Win32Types.DisplayInfo di = new Win32Types.DisplayInfo();
                    di.ScreenWidth            = (mi.rcMonitor.Right - mi.rcMonitor.Left).ToString();
                    di.ScreenHeight           = (mi.rcMonitor.Bottom - mi.rcMonitor.Top).ToString();
                    di.MonitorArea            = mi.rcMonitor;
                    di.WorkArea     = mi.rcWork;
                    di.Availability = mi.dwFlags.ToString();
                    di.hwnd         = hMonitor;
                    displayList.Add(di);
                }
                return(1);
            }, IntPtr.Zero);
            return(displayList);
        }