diff --git a/DisplaySettings/DisplaySettings.csproj b/DisplaySettings/DisplaySettings.csproj index 9eecdd2..a13a1e8 100644 --- a/DisplaySettings/DisplaySettings.csproj +++ b/DisplaySettings/DisplaySettings.csproj @@ -3,7 +3,7 @@ netstandard2.0 biosmanager - 1.0.0 + 1.0.1 Library to change or retrieve display information and settings. Copyright © 2020 biosmanager LICENSE.md @@ -12,6 +12,12 @@ git true false + $(BaseOutputPath)\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + + + + none + false diff --git a/DisplaySettings/Source/DisplayInformation.cs b/DisplaySettings/Source/DisplayInformation.cs index 05fcbe2..26f0bfe 100644 --- a/DisplaySettings/Source/DisplayInformation.cs +++ b/DisplaySettings/Source/DisplayInformation.cs @@ -7,44 +7,126 @@ namespace DisplaySettings { /// - /// Contains information about about a display adapter and all its monitors + /// Contains information about about a display adapter and all its monitors. /// public sealed class DisplayInformation { - // Flags based on wingdi.h from Windows SDK 10.0.16299.0 + /// + /// States of a of display adapter or monitor. + /// + /// + /// Flags based on wingdi.h from Windows SDK 10.0.16299.0. + /// [Flags] public enum DisplayDeviceStateFlags : uint { + /// + /// Device is currently attached to the desktop. + /// AttachedToDesktop = 0x00000001, + /// + /// Not documented. + /// MultiDriver = 0x00000002, + /// + /// Device is the primary device. + /// PrimaryDevice = 0x00000004, + /// + /// Device is mirroring another device. + /// MirroringDriver = 0x00000008, + /// + /// Not documented. + /// VgaCompatible = 0x00000010, + /// + /// Not documented. + /// Removable = 0x00000020, + /// + /// Not documented. + /// AccDriver = 0x00000040, + /// + /// Not documented. + /// ModesPruned = 0x08000000, + /// + /// Not documented. + /// RdpUdd = 0x01000000, + /// + /// Not documented. + /// Remote = 0x04000000, + /// + /// Not documented. + /// Disconnect = 0x02000000, + /// + /// Not documented. + /// TSCompatible = 0x00200000, + /// + /// Device has unsafe graphics modes enabled. + /// UnsafeModesOn = 0x00080000 } + /// + /// Monitor device + /// public sealed class Monitor { + /// + /// Index on adapter. It can be -1 if the mode cannot be found in all available modes for a display. + /// public int MonitorIndex { get; set; } + /// + /// Path on adapter. + /// public string Name { get; set; } + /// + /// Name of the monitor. + /// public string Description { get; set; } + /// + /// Current states of the monitor. + /// public DisplayDeviceStateFlags StateFlags { get; set; } + /// + /// Device interface name and GUID. Can be used with SetupAPI. + /// public string InterfaceName { get; set; } } + /// + /// Index of the adapter/display. + /// public int DisplayIndex { get; set; } + /// + /// Adapter path. + /// public string AdapterName { get; set; } + /// + /// Name of the adapter. + /// public string AdapterDescription { get; set; } + /// + /// Current states of the adapter. + /// public DisplayDeviceStateFlags AdapterStateFlags { get; set; } + /// + /// All monitors associated with the adapter. + /// public Monitor[] Monitors { get; set; } + + /// + /// Retrieves information about the adapter/display and its associated monitors. + /// + /// Adapter/display of interest. public static DisplayInformation GetAdapterAndDisplayInformation(int displayIndex) { displayIndex = Math.Max(displayIndex, 0); @@ -75,6 +157,11 @@ public static DisplayInformation GetAdapterAndDisplayInformation(int displayInde return displayInfo; } + /// + /// Lists all displays on the system. + /// + /// Determines if only displays/adapters that are attached to the desktop should be considered. + /// Can be empty if no adapters/displays are present. public static DisplayInformation[] EnumerateAllDisplays(bool doOnlyListAttached = false) { var displayInformations = new List(); @@ -119,6 +206,9 @@ public static DisplayInformation[] EnumerateAllDisplays(bool doOnlyListAttached return displayInformations.ToArray(); } + /// + /// Find index of primary display/adapter. + /// public static int FindPrimaryDisplayIndex() { var devices = EnumerateAllDisplays(true); diff --git a/DisplaySettings/Source/DisplaySettings.cs b/DisplaySettings/Source/DisplaySettings.cs index 922d794..37d7fe9 100644 --- a/DisplaySettings/Source/DisplaySettings.cs +++ b/DisplaySettings/Source/DisplaySettings.cs @@ -5,26 +5,66 @@ namespace DisplaySettings { + /// + /// Holds settings for a display. + /// public sealed class DisplaySettings { + /// + /// Result of display settings change operation. See . + /// public sealed class DisplaySettingsChangedResult { + /// + /// Possible status code of native ChangeDisplaySettingsExfunction. + /// public enum ChangeStatus : int { + /// + /// The settings change was successful. + /// SUCCESSFUL = 0, + /// + /// The computer must be restarted for the graphics mode to work. + /// RESTART = 1, + /// + /// The display driver failed the specified graphics mode. + /// FAILED = -1, + /// + /// The graphics mode is not supported. + /// BADMODE = -2, + /// + /// Unable to write settings to the registry. + /// NOTUPDATED = -3, + /// + /// An invalid set of flags was passed in. + /// BADFLAGS = -4, + /// + /// An invalid parameter was passed in. This can include an invalid flag or combination of flags. + /// BADPARAM = -5, + /// + /// The settings change was unsuccessful because the system is DualView capable. + /// BADDUALVIEW = -6 } + /// + /// Return status reported by ChangeDisplaySettingsEx. + /// public ChangeStatus Status { get; private set; } + /// + /// Description of the result. + /// public string Description { get; private set; } - public DisplaySettingsChangedResult(ChangeStatus status) + + internal DisplaySettingsChangedResult(ChangeStatus status) { Status = status; switch (Status) @@ -59,39 +99,92 @@ public DisplaySettingsChangedResult(ChangeStatus status) }; } - public DisplaySettingsChangedResult(int status) : this((ChangeStatus)status) + internal DisplaySettingsChangedResult(int status) : this((ChangeStatus)status) { } } + /// + /// Type of the display settings to report, either the currently set or those stored in the registry. See . + /// public enum SettingsType : int { + /// + /// Use current settings. + /// Current = ENUM_CURRENT_SETTINGS, + /// + /// Use settings stored in registry. + /// Registry = ENUM_REGISTRY_SETTINGS } + /// + /// Graphics mode. + /// public sealed class GraphicsMode { + /// + /// Index of the mode. + /// public int Index { get; set; } + /// + /// Width of the resolution in pixels. + /// public int Width { get; set; } + /// + /// Height of the resolution in pixels. + /// public int Height { get; set; } + /// + /// Vertical refresh rate in Hz. + /// public int RefreshRate { get; set; } + /// + /// Bit depth in total bits per pixel for all channels. + /// public int BitDepth { get; set; } } + /// + /// Position of upper left corner of a display in desktop configuration. The primary display is always at (0,0). + /// public struct Position { + /// + /// X + /// public int X { get; set; } + /// + /// Y + /// public int Y { get; set; } } + /// + /// Index of the display/adapter. + /// public int DisplayIndex { get; set; } + /// + /// Graphics mode. + /// public GraphicsMode Mode { get; set; } + /// + /// Position in desktop configuration. + /// public Position DesktopPosition { get; set; } + /// + /// Whether the display/adapter is attached to the desktop. + /// public bool IsAttached { get; set; } + /// + /// Change settings of a display. + /// + /// The settings to apply. + /// Result of the operation including a description. public static DisplaySettingsChangedResult ChangeDisplaySettings(DisplaySettings displaySettings) { displaySettings.DisplayIndex = Math.Max(displaySettings.DisplayIndex, 0); @@ -129,6 +222,11 @@ public static DisplaySettingsChangedResult ChangeDisplaySettings(DisplaySettings } } + /// + /// Retrieve display settings. + /// + /// Index of the display/adapter of interest. + /// Whether to retrieve the currently active settings or those stored in the registry for that display/adapter. public static DisplaySettings GetDisplaySettings(int displayIndex, SettingsType type = SettingsType.Current) { displayIndex = Math.Max(displayIndex, 0); @@ -173,6 +271,10 @@ public static DisplaySettings GetDisplaySettings(int displayIndex, SettingsType return displaySettings; } + /// + /// List all graphics modes supported by a display. + /// + /// Index of the display/adapter of interest. public static GraphicsMode[] EnumerateAllDisplayModes(int displayIndex) { var displayModes = new List(); diff --git a/DisplaySettings/Source/Util.cs b/DisplaySettings/Source/Util.cs index 12dfb34..79bd608 100644 --- a/DisplaySettings/Source/Util.cs +++ b/DisplaySettings/Source/Util.cs @@ -4,8 +4,16 @@ namespace DisplaySettings { + /// + /// Holds various utility methods. + /// public static class Util { + /// + /// Get name for commonly used bit depths. + /// + /// Bit depth in bits per pixel for all channels. + /// High Color for 24 bit, True Color for 32 bit, empty string for all other bit depths. public static string BitDepthToName(int bitDepth) { switch (bitDepth)