EnumDisplaySettings() private method

private EnumDisplaySettings ( [ device_name, DisplayModeSettingsEnum graphics_mode, [ device_mode ) : BOOL
device_name [
graphics_mode DisplayModeSettingsEnum
device_mode [
return BOOL
Example #1
0
            new Dictionary <DisplayDevice, string>();    // Needed for ChangeDisplaySettingsEx
        #region --- Constructors ---

        /// <summary>Queries available display devices and display resolutions.</summary>
        static WinDisplayDeviceDriver()
        {
            lock (display_lock)
            {
                // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
                // we only allow settings to be set through its constructor.
                // Thus, we save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                DisplayDevice            opentk_dev;
                DisplayResolution        opentk_dev_current_res   = null;
                List <DisplayResolution> opentk_dev_available_res = new List <DisplayResolution>();
                bool opentk_dev_primary = false;
                int  device_count = 0, mode_count = 0;
                // Get available video adapters and enumerate all monitors
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                    {
                        continue;
                    }
                    DeviceMode monitor_mode = new DeviceMode();
                    // The second function should only be executed when the first one fails
                    // (e.g. when the monitor is disabled)
                    if (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        opentk_dev_current_res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                        opentk_dev_primary =
                            (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                    }

                    opentk_dev_available_res.Clear();
                    mode_count = 0;
                    while (Functions.EnumDisplaySettings(dev1.DeviceName.ToString(), mode_count++, monitor_mode))
                    {
                        DisplayResolution res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds);
                    available_device_names.Add(opentk_dev, dev1.DeviceName);
                }
            }
        }
 public void RefreshDisplayDevices()
 {
     lock (this.display_lock)
     {
         this.AvailableDevices.Clear();
         DisplayResolution        local_1 = (DisplayResolution)null;
         List <DisplayResolution> local_2 = new List <DisplayResolution>();
         bool local_3 = false;
         int  local_4 = 0;
         WindowsDisplayDevice local_6 = new WindowsDisplayDevice();
         WindowsDisplayDevice temp_10 = new WindowsDisplayDevice();
         while (Functions.EnumDisplayDevices((string)null, local_4++, local_6, 0))
         {
             if ((local_6.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) != DisplayDeviceStateFlags.None)
             {
                 DeviceMode local_7 = new DeviceMode();
                 if (Functions.EnumDisplaySettingsEx(((object)local_6.DeviceName).ToString(), DisplayModeSettingsEnum.CurrentSettings, local_7, 0) || Functions.EnumDisplaySettingsEx(((object)local_6.DeviceName).ToString(), DisplayModeSettingsEnum.RegistrySettings, local_7, 0))
                 {
                     local_1 = new DisplayResolution(local_7.Position.X, local_7.Position.Y, local_7.PelsWidth, local_7.PelsHeight, local_7.BitsPerPel, (float)local_7.DisplayFrequency);
                     local_3 = (local_6.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                 }
                 local_2.Clear();
                 int local_5_1 = 0;
                 while (Functions.EnumDisplaySettings(((object)local_6.DeviceName).ToString(), local_5_1++, local_7))
                 {
                     DisplayResolution local_8 = new DisplayResolution(local_7.Position.X, local_7.Position.Y, local_7.PelsWidth, local_7.PelsHeight, local_7.BitsPerPel, (float)local_7.DisplayFrequency);
                     local_2.Add(local_8);
                 }
                 DisplayDevice local_0 = new DisplayDevice(local_1, local_3, (IEnumerable <DisplayResolution>)local_2, local_1.Bounds, (object)local_6.DeviceName);
                 this.AvailableDevices.Add(local_0);
                 if (local_3)
                 {
                     this.Primary = local_0;
                 }
             }
         }
     }
 }