/// <summary>Returns a read-only collection containing information about all the graphics modes for a display device.</summary> /// <param name="deviceName">A string that specifies the display device about which graphics modes the function will obtain information. /// <para>This parameter is either null or a <see cref="DisplayDevice.DeviceName"/> returned from EnumDisplayDevicesW.</para> /// A null value specifies the current display device on the computer that the calling thread is running on.</param> /// <param name="options">One or more <see cref="EnumDisplaySettingsExOptions"/>.</param> /// <returns>Returns a read-only collection containing information about all the graphics modes for a display device.</returns> private static ReadOnlyCollection <DisplayDeviceMode> EnumDisplaySettingsEx(string deviceName, EnumDisplaySettingsExOptions options) { var modes = new List <DisplayDeviceMode>(); var devMode = DisplayDeviceMode.Default; var modeIndex = 0; while (NativeMethods.EnumDisplaySettingsExW(deviceName, modeIndex++, ref devMode, options)) { if (!devMode.Width.HasValue || !devMode.Height.HasValue || !devMode.DisplayFrequency.HasValue) { continue; } // basic filtering: we don't need display modes whose width, height or frequency is missing. if (!devMode.BitsPerPixel.HasValue || devMode.BitsPerPixel.Value != 32) { continue; } // 8, 16 and 24 bpp modes are no more supported, since Windows 7. if (devMode.IsGrayscale.HasValue && devMode.IsGrayscale.Value) { continue; } // Only 32 bpp modes are supported, so grayscale modes should be safely ignored. modes.Add(devMode); } if (modes.Count > 1) { modes.Sort((DisplayDeviceMode mode, DisplayDeviceMode other) => { return(-mode.CompareTo(other)); }); } return(new ReadOnlyCollection <DisplayDeviceMode>(modes)); }
/// <summary>Returns information about the display mode of a display adapter, as stored in the registry.</summary> /// <param name="deviceName">A string that specifies the display device about which graphics mode the function will obtain information. /// <para>This parameter is either null or a <see cref="DisplayDevice.DeviceName"/> returned from <see cref="NativeMethods.EnumDisplayDevicesW"/>.</para> /// A null value specifies the current display device on the computer that the calling thread is running on.</param> /// <param name="options">One or more <see cref="EnumDisplaySettingsExOptions"/>.</param> /// <returns>Returns information about the display mode of a display adapter, as stored in the registry.</returns> private static DisplayDeviceMode GetRegistryDisplaySettingsEx(string deviceName, EnumDisplaySettingsExOptions options) { var output = DisplayDeviceMode.Default; if (!NativeMethods.EnumDisplaySettingsExW(deviceName, -2, ref output, options)) { output = DisplayDeviceMode.Default; } return(output); }
/// <summary>Returns information about the display mode of a display adapter, as stored in the registry.</summary> /// <param name="deviceName">A string that specifies the display device about which graphics mode the function will obtain information. /// <para>This parameter is either null or a <see cref="DisplayDevice.DeviceName"/> returned from <see cref="EnumDisplayDevicesW"/>.</para> /// A null value specifies the current display device on the computer that the calling thread is running on.</param> /// <param name="options">One or more <see cref="EnumDisplaySettingsExOptions"/>.</param> /// <returns>Returns information about the display mode of a display adapter, as stored in the registry.</returns> internal static DisplayDeviceMode GetRegistryDisplaySettingsEx( string deviceName, EnumDisplaySettingsExOptions options ) { var output = DisplayDeviceMode.Default; if( !EnumDisplaySettingsExW( deviceName, -2, ref output, options ) ) output = DisplayDeviceMode.Default; return output; }
internal static extern bool EnumDisplaySettingsExW( [In, MarshalAs(UnmanagedType.LPWStr)] string deviceName, [In] int modeIndex, [In, Out] ref DisplayDeviceMode devMode, [In] EnumDisplaySettingsExOptions options );
//BOOL EnumDisplaySettingsEx( // _In_opt_ LPCWSTR lpszDeviceName, // _In_ DWORD iModeNum, // _Inout_ DEVMODEW* lpDevMode, // _In_ DWORD dwFlags); /// <summary>Returns a read-only collection containing information about all the graphics modes for a display device.</summary> /// <param name="deviceName">A string that specifies the display device about which graphics modes the function will obtain information. /// <para>This parameter is either null or a <see cref="DisplayDevice.DeviceName"/> returned from <see cref="EnumDisplayDevicesW"/>.</para> /// A null value specifies the current display device on the computer that the calling thread is running on.</param> /// <param name="options">One or more <see cref="EnumDisplaySettingsExOptions"/>.</param> /// <returns>Returns a read-only collection containing information about all the graphics modes for a display device.</returns> internal static ReadOnlyDisplayDeviceModeCollection EnumDisplaySettingsEx( string deviceName, EnumDisplaySettingsExOptions options ) { var modes = new List<DisplayDeviceMode>(); var devMode = DisplayDeviceMode.Default; var modeIndex = 0; while( EnumDisplaySettingsExW( deviceName, modeIndex++, ref devMode, options ) ) { if( !devMode.Width.HasValue || !devMode.Height.HasValue || !devMode.DisplayFrequency.HasValue ) continue; // basic filtering: we don't need display modes whose width, height or frequency is missing. if( !devMode.BitsPerPixel.HasValue || devMode.BitsPerPixel.Value != 32 ) continue; // 8, 16 and 24 bpp modes are no more supported, since Windows 7. if( devMode.IsGrayscale.HasValue && devMode.IsGrayscale.Value ) continue; // Only 32 bpp modes are supported, so grayscale modes should be safely ignored. modes.Add( devMode ); } if( modes.Count > 1 ) modes.Sort( ( DisplayDeviceMode mode, DisplayDeviceMode other ) => { return -mode.CompareTo( other ); } ); return new ReadOnlyDisplayDeviceModeCollection( modes ); }