public static List <DisplayDevice> GetAvailableDevices(bool list_all)
        {
            int index = 0;
            List <DisplayDevice>    list = new List <DisplayDevice>();
            DisplayDeviceInfoStruct dd   = new DisplayDeviceInfoStruct();

            while (IGE.Platform.Win32.API.Externals.EnumDisplayDevices(null, index++, dd, 1))
            {
                if (!list_all)
                {
                    if ((dd.StateFlags & DisplayDeviceStateFlags.Active) != DisplayDeviceStateFlags.Active)
                    {
                        continue;
                    }
                    if ((dd.StateFlags & DisplayDeviceStateFlags.MirroringDriver) == DisplayDeviceStateFlags.MirroringDriver)
                    {
                        continue;
                    }
                }
                GameDebugger.EngineLog(LogLevel.Debug, "Found display device: Id={0}; Key={1}; Name={2}; String={3}; Flags={4}", dd.DeviceID, dd.DeviceKey, dd.DeviceName, dd.DeviceString, dd.StateFlags);
                list.Add(new DisplayDevice(dd));
                dd = new DisplayDeviceInfoStruct();
            }
            return(list);
        }
        /// <summary>
        /// Creates an instance of a display device
        /// </summary>
        /// <param name="index">Index of the display device with base on 1. If the display with selected index does not exist, this object will be created for the primary display device (same as calling static method DisplayDevice.GetPrimary()).</param>
        public DisplayDevice(string id)
        {
            GameDebugger.EngineLog(LogLevel.Debug, "Searching for display device '{0}'", id);
            m_DeviceInfo = new DisplayDeviceInfoStruct();
            m_Exists     = false;
            List <DisplayDevice> devices = DisplayDevice.GetAvailableDevices();

            if (id != null)
            {
                foreach (DisplayDevice dev in devices)
                {
                    if (dev.Id.Equals(id))
                    {
                        m_DeviceInfo = dev.m_DeviceInfo;
                        m_Exists     = true;
                        break;
                    }
                }
            }
            if (!m_Exists)
            {
                GameDebugger.EngineLog(LogLevel.Notice, "Did not find a requested display device. Using primary display device instead.");
                foreach (DisplayDevice dev in devices)
                {
                    if (dev.Primary)
                    {
                        GameDebugger.EngineLog(LogLevel.Debug, "Primary display device found.");
                        m_DeviceInfo = dev.m_DeviceInfo;
                        m_Exists     = true;
                        break;
                    }
                }
            }
            if (m_Exists)
            {
                DisplayMode.ResolutionChangeEvent += RefreshMonitorData;
                RefreshMonitorData();
            }
            else
            {
                GameDebugger.EngineLog(LogLevel.Error, "Primary display device not found.");
            }
        }
Esempio n. 3
0
 public static extern Boolean EnumDisplayDevices([MarshalAs(UnmanagedType.LPTStr)] string device_name, int iDevNum, [In, Out] DisplayDeviceInfoStruct lpDisplayDevice, int dwFlags);
 private DisplayDevice(DisplayDeviceInfoStruct dd)
 {
     m_Exists     = true;
     m_DeviceInfo = dd;
     RefreshMonitorData();
 }