diff --git a/PInvoke/Gdi32/WinGdi.Display.cs b/PInvoke/Gdi32/WinGdi.Display.cs new file mode 100644 index 00000000..d578a539 --- /dev/null +++ b/PInvoke/Gdi32/WinGdi.Display.cs @@ -0,0 +1,1270 @@ +using System; +using System.Drawing; +using System.Runtime.InteropServices; +using Vanara.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class Gdi32 + { + /// Undocumented. + [PInvokeData("wingdi.h")] + public enum DISPLAYCONFIG_COLOR_ENCODING : uint + { + /// Undocumented. + DISPLAYCONFIG_COLOR_ENCODING_RGB = 0, + + /// Undocumented. + DISPLAYCONFIG_COLOR_ENCODING_YCBCR444 = 1, + + /// Undocumented. + DISPLAYCONFIG_COLOR_ENCODING_YCBCR422 = 2, + + /// Undocumented. + DISPLAYCONFIG_COLOR_ENCODING_YCBCR420 = 3, + + /// Undocumented. + DISPLAYCONFIG_COLOR_ENCODING_INTENSITY = 4, + } + + /// + /// + /// The DISPLAYCONFIG_DEVICE_INFO_TYPE enumeration specifies the type of display device info to configure or obtain through the + /// DisplayConfigSetDeviceInfo or DisplayConfigGetDeviceInfo function. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ne-wingdi-displayconfig_device_info_type typedef enum { + // DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME, + // DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE, DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME, + // DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE, DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE, + // DISPLAYCONFIG_DEVICE_INFO_GET_SUPPORT_VIRTUAL_RESOLUTION, DISPLAYCONFIG_DEVICE_INFO_SET_SUPPORT_VIRTUAL_RESOLUTION, + // DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO, DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE, + // DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL, DISPLAYCONFIG_DEVICE_INFO_FORCE_UINT32 } ; + [PInvokeData("wingdi.h", MSDNShortId = "40cc67c0-1508-4b67-b297-5a8dabaabb16")] + public enum DISPLAYCONFIG_DEVICE_INFO_TYPE : uint + { + /// + /// Specifies the source name of the display device. If the DisplayConfigGetDeviceInfo function is successful, + /// DisplayConfigGetDeviceInfo returns the source name in the DISPLAYCONFIG_SOURCE_DEVICE_NAME structure. + /// + [CorrespondingType(typeof(DISPLAYCONFIG_SOURCE_DEVICE_NAME), CorrepsondingAction.Get)] + DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1, + + /// + /// Specifies information about the monitor. If the DisplayConfigGetDeviceInfo function is successful, DisplayConfigGetDeviceInfo + /// returns info about the monitor in the DISPLAYCONFIG_TARGET_DEVICE_NAME structure. + /// + [CorrespondingType(typeof(DISPLAYCONFIG_TARGET_DEVICE_NAME), CorrepsondingAction.Get)] + DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME, + + /// + /// Specifies information about the preferred mode of a monitor. If the DisplayConfigGetDeviceInfo function is successful, + /// DisplayConfigGetDeviceInfo returns info about the preferred mode of a monitor in the DISPLAYCONFIG_TARGET_PREFERRED_MODE structure. + /// + [CorrespondingType(typeof(DISPLAYCONFIG_TARGET_PREFERRED_MODE), CorrepsondingAction.Get)] + DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE, + + /// + /// Specifies the graphics adapter name. If the DisplayConfigGetDeviceInfo function is successful, DisplayConfigGetDeviceInfo + /// returns the adapter name in the DISPLAYCONFIG_ADAPTER_NAME structure. + /// + [CorrespondingType(typeof(DISPLAYCONFIG_ADAPTER_NAME), CorrepsondingAction.Get)] + DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME, + + /// + /// Specifies how to set the monitor. If the DisplayConfigSetDeviceInfo function is successful, DisplayConfigSetDeviceInfo uses + /// info in the DISPLAYCONFIG_SET_TARGET_PERSISTENCE structure to force the output in a boot-persistent manner. + /// + [CorrespondingType(typeof(DISPLAYCONFIG_SET_TARGET_PERSISTENCE), CorrepsondingAction.Set)] + DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE, + + /// + /// Specifies how to set the base output technology for a given target ID. If the DisplayConfigGetDeviceInfo function is + /// successful, DisplayConfigGetDeviceInfo returns base output technology info in the DISPLAYCONFIG_TARGET_BASE_TYPE structure. + /// Supported by WDDM 1.3 and later user-mode display drivers running on Windows 8.1 and later. + /// + [CorrespondingType(typeof(DISPLAYCONFIG_TARGET_BASE_TYPE), CorrepsondingAction.Get)] + DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE, + + /// + /// Specifies the state of virtual mode support. If the DisplayConfigGetDeviceInfo function is successful, + /// DisplayConfigGetDeviceInfo returns virtual mode support information in the DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION + /// structure. Supported starting in Windows 10. + /// + [CorrespondingType(typeof(DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION), CorrepsondingAction.Get)] + DISPLAYCONFIG_DEVICE_INFO_GET_SUPPORT_VIRTUAL_RESOLUTION, + + /// + /// Specifies how to set the state of virtual mode support. If the DisplayConfigGetDeviceInfo function is successful, + /// DisplayConfigGetDeviceInfo uses info in the DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION structure to change the state of virtual + /// mode support. Supported starting in Windows 10. + /// + [CorrespondingType(typeof(DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION), CorrepsondingAction.Set)] + DISPLAYCONFIG_DEVICE_INFO_SET_SUPPORT_VIRTUAL_RESOLUTION, + + /// + [CorrespondingType(typeof(DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO), CorrepsondingAction.Get)] + DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO, + + /// + [CorrespondingType(typeof(DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE), CorrepsondingAction.Set)] + DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE, + + /// + [CorrespondingType(typeof(DISPLAYCONFIG_SDR_WHITE_LEVEL), CorrepsondingAction.Get)] + DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL, + } + + /// Undocumented. + [PInvokeData("wingdi.h")] + [Flags] + public enum DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_VALUE + { + /// A type of advanced color is supported + advancedColorSupported = 1, + + /// A type of advanced color is enabled + advancedColorEnabled = 2, + + /// Wide color gamut is enabled + wideColorEnforced = 4, + + /// Advanced color is force disabled due to system/OS policy + advancedColorForceDisabled = 8, + } + + /// + /// The DISPLAYCONFIG_MODE_INFO_TYPE enumeration specifies that the information that is contained within the DISPLAYCONFIG_MODE_INFO + /// structure is either source or target mode. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ne-wingdi-__unnamed_enum_4 typedef enum { + // DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE, DISPLAYCONFIG_MODE_INFO_TYPE_TARGET, DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE, + // DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32 } ; + [PInvokeData("wingdi.h", MSDNShortId = "d5ddb1d5-6b74-471f-86f0-fee72f30b648")] + public enum DISPLAYCONFIG_MODE_INFO_TYPE : uint + { + /// Indicates that the DISPLAYCONFIG_MODE_INFO structure contains source mode information. + DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE = 1, + + /// Indicates that the DISPLAYCONFIG_MODE_INFO structure contains target mode information. + DISPLAYCONFIG_MODE_INFO_TYPE_TARGET, + + /// + /// Indicates that the DISPLAYCONFIG_MODE_INFO structure contains a valid DISPLAYCONFIG_DESKTOP_IMAGE_INFO structure. Supported + /// starting in Windows 10. + /// + DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE, + } + + /// The DISPLAYCONFIG_PIXELFORMAT enumeration specifies pixel format in various bits per pixel (BPP) values. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ne-wingdi-displayconfig_pixelformat typedef enum { + // DISPLAYCONFIG_PIXELFORMAT_8BPP, DISPLAYCONFIG_PIXELFORMAT_16BPP, DISPLAYCONFIG_PIXELFORMAT_24BPP, DISPLAYCONFIG_PIXELFORMAT_32BPP, + // DISPLAYCONFIG_PIXELFORMAT_NONGDI, DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32 } ; + [PInvokeData("wingdi.h", MSDNShortId = "dca8433d-89a9-492c-bebb-6a28f485896c")] + public enum DISPLAYCONFIG_PIXELFORMAT : uint + { + /// Indicates 8 BPP format. + DISPLAYCONFIG_PIXELFORMAT_8BPP = 1, + + /// Indicates 16 BPP format. + DISPLAYCONFIG_PIXELFORMAT_16BPP, + + /// Indicates 24 BPP format. + DISPLAYCONFIG_PIXELFORMAT_24BPP, + + /// Indicates 32 BPP format. + DISPLAYCONFIG_PIXELFORMAT_32BPP, + + /// + /// Indicates that the current display is not an 8, 16, 24, or 32 BPP GDI desktop mode. For example, a call to the + /// QueryDisplayConfig function returns DISPLAYCONFIG_PIXELFORMAT_NONGDI if a DirectX application previously set the desktop to + /// A2R10G10B10 format. A call to the SetDisplayConfig function fails if any pixel formats for active paths are set to DISPLAYCONFIG_PIXELFORMAT_NONGDI. + /// + DISPLAYCONFIG_PIXELFORMAT_NONGDI, + } + + /// The DISPLAYCONFIG_ROTATION enumeration specifies the clockwise rotation of the display. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ne-wingdi-displayconfig_rotation typedef enum { + // DISPLAYCONFIG_ROTATION_IDENTITY, DISPLAYCONFIG_ROTATION_ROTATE90, DISPLAYCONFIG_ROTATION_ROTATE180, + // DISPLAYCONFIG_ROTATION_ROTATE270, DISPLAYCONFIG_ROTATION_FORCE_UINT32 } ; + [PInvokeData("wingdi.h", MSDNShortId = "82709d44-45e6-47ec-9caa-5a947a568c52")] + public enum DISPLAYCONFIG_ROTATION : uint + { + /// Indicates that rotation is 0 degrees—landscape mode. + DISPLAYCONFIG_ROTATION_IDENTITY = 1, + + /// Indicates that rotation is 90 degrees clockwise—portrait mode. + DISPLAYCONFIG_ROTATION_ROTATE90, + + /// Indicates that rotation is 180 degrees clockwise—inverted landscape mode. + DISPLAYCONFIG_ROTATION_ROTATE180, + + /// Indicates that rotation is 270 degrees clockwise—inverted portrait mode. + DISPLAYCONFIG_ROTATION_ROTATE270, + } + + /// + /// The DISPLAYCONFIG_SCALING enumeration specifies the scaling transformation applied to content displayed on a video present + /// network (VidPN) present path. + /// + /// For more information about scaling, see Scaling the Desktop Image. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ne-wingdi-displayconfig_scaling typedef enum { + // DISPLAYCONFIG_SCALING_IDENTITY, DISPLAYCONFIG_SCALING_CENTERED, DISPLAYCONFIG_SCALING_STRETCHED, + // DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX, DISPLAYCONFIG_SCALING_CUSTOM, DISPLAYCONFIG_SCALING_PREFERRED, + // DISPLAYCONFIG_SCALING_FORCE_UINT32 } ; + [PInvokeData("wingdi.h", MSDNShortId = "6f073aa6-2647-4a51-9256-b2da488fd382")] + public enum DISPLAYCONFIG_SCALING : uint + { + /// + /// Indicates the identity transformation; the source content is presented with no change. This transformation is available only + /// if the path's source mode has the same spatial resolution as the path's target mode. + /// + DISPLAYCONFIG_SCALING_IDENTITY = 1, + + /// + /// Indicates the centering transformation; the source content is presented unscaled, centered with respect to the spatial + /// resolution of the target mode. + /// + DISPLAYCONFIG_SCALING_CENTERED, + + /// Indicates the content is scaled to fit the path's target. + DISPLAYCONFIG_SCALING_STRETCHED, + + /// Indicates the aspect-ratio centering transformation. + DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX, + + /// + /// Indicates that the caller requests a custom scaling that the caller cannot describe with any of the other + /// DISPLAYCONFIG_SCALING_XXX values. Only a hardware vendor's value-add application should use DISPLAYCONFIG_SCALING_CUSTOM, + /// because the value-add application might require a private interface to the driver. The application can then use + /// DISPLAYCONFIG_SCALING_CUSTOM to indicate additional context for the driver for the custom value on the specified path. + /// + DISPLAYCONFIG_SCALING_CUSTOM, + + /// + /// Indicates that the caller does not have any preference for the scaling. The SetDisplayConfig function will use the scaling + /// value that was last saved in the database for the path. If such a scaling value does not exist, SetDisplayConfig will use the + /// default scaling for the computer. For example, stretched (DISPLAYCONFIG_SCALING_STRETCHED) for tablet computers and + /// aspect-ratio centered (DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX) for non-tablet computers. + /// + DISPLAYCONFIG_SCALING_PREFERRED = 128, + } + + /// + /// The DISPLAYCONFIG_SCANLINE_ORDERING enumeration specifies the method that the display uses to create an image on a screen. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ne-wingdi-__unnamed_enum_1 typedef enum { + // DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED, DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE, + // DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED, DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST, + // DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST, DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 } ; + [PInvokeData("wingdi.h", MSDNShortId = "5b8d6c83-e8fb-4529-8d61-557ed0e4da37")] + public enum DISPLAYCONFIG_SCANLINE_ORDERING : uint + { + /// + /// Indicates that scan-line ordering of the output is unspecified. The caller can only set the scanLineOrdering member of the + /// DISPLAYCONFIG_PATH_TARGET_INFO structure in a call to the SetDisplayConfig function to + /// DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED if the caller also set the refresh rate denominator and numerator of the + /// refreshRate member both to zero. In this case, SetDisplayConfig uses the best refresh rate it can find. + /// + DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = 0, + + /// Indicates that the output is a progressive image. + DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE = 1, + + /// Indicates that the output is an interlaced image that is created beginning with the upper field. + DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED = 2, + + /// Indicates that the output is an interlaced image that is created beginning with the upper field. + DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST = DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED, + + /// Indicates that the output is an interlaced image that is created beginning with the lower field. + DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = 3, + } + + /// Undocumented. + [PInvokeData("wingdi.h")] + public enum DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE_VALUE + { + /// Undocumented. + enableAdvancedColor = 1 + } + + /// + /// A member in the union that DISPLAYCONFIG_SET_TARGET_PERSISTENCE contains that can hold a 32-bit value that identifies information + /// about setting the display. + /// + [PInvokeData("wingdi.h", MSDNShortId = "4798a1e1-8685-40c2-917a-0ee071bc780c")] + [Flags] + public enum DISPLAYCONFIG_SET_TARGET_PERSISTENCE_VALUE : uint + { + /// + /// + /// A UINT32 value that specifies whether the SetDisplayConfig function should enable or disable boot persistence for the + /// specified target. + /// + /// Setting this member is equivalent to setting the first bit of the 32-bit value member (0x00000001). + /// + bootPersistenceOn = 1, + } + + /// Reflects the value of disableMonitorVirtualResolution in cases where debugging is utilized. + [PInvokeData("wingdi.h", MSDNShortId = "D9208D00-F437-4B2E-8C39-044F75088659")] + [Flags] + public enum DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION_VALUE : uint + { + /// Setting this bit disables virtual mode for the monitor using information found in header. + disableMonitorVirtualResolution = 1 + } + + /// The DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS enum contains information about a target device. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_target_device_name_flags typedef struct + // DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS { union { struct { UINT32 friendlyNameFromEdid : 1; UINT32 friendlyNameForced : 1; UINT32 + // edidIdsValid : 1; UINT32 reserved : 29; } DUMMYSTRUCTNAME; UINT32 value; } DUMMYUNIONNAME; } DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS; + [PInvokeData("wingdi.h", MSDNShortId = "f0318dd3-4350-4de3-84c8-2c998254c68c")] + public enum DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS : uint + { + /// + /// Indicates that the string in the monitorFriendlyDeviceName member of the DISPLAYCONFIG_TARGET_DEVICE_NAME structure was + /// constructed from the manufacture identification string in the extended display identification data (EDID). + /// + friendlyNameFromEdid = 1, + + /// + /// Indicates that the target is forced with no detectable monitor attached and the monitorFriendlyDeviceName member of the + /// DISPLAYCONFIG_TARGET_DEVICE_NAME structure is a NULL-terminated empty string. + /// + friendlyNameForced = 2, + + /// + /// Indicates that the edidManufactureId and edidProductCodeId members of the DISPLAYCONFIG_TARGET_DEVICE_NAME structure are + /// valid and were obtained from the EDID. + /// + edidIdsValid = 4 + } + + /// The DISPLAYCONFIG_TOPOLOGY_ID enumeration specifies the type of display topology. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ne-wingdi-displayconfig_topology_id typedef enum + // DISPLAYCONFIG_TOPOLOGY_ID { DISPLAYCONFIG_TOPOLOGY_INTERNAL, DISPLAYCONFIG_TOPOLOGY_CLONE, DISPLAYCONFIG_TOPOLOGY_EXTEND, + // DISPLAYCONFIG_TOPOLOGY_EXTERNAL, DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32 } ; + [PInvokeData("wingdi.h", MSDNShortId = "0018f137-7cdf-47b7-9ede-8685f9b073fb")] + [Flags] + public enum DISPLAYCONFIG_TOPOLOGY_ID : uint + { + /// Indicates that the display topology is an internal configuration. + DISPLAYCONFIG_TOPOLOGY_INTERNAL = 1, + + /// Indicates that the display topology is clone-view configuration. + DISPLAYCONFIG_TOPOLOGY_CLONE = 2, + + /// Indicates that the display topology is an extended configuration. + DISPLAYCONFIG_TOPOLOGY_EXTEND = 4, + + /// Indicates that the display topology is an external configuration. + DISPLAYCONFIG_TOPOLOGY_EXTERNAL = 8, + } + + /// The DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY enumeration specifies the target's connector type. + /// + /// + /// Values with "embedded" in their names indicate that the graphics adapter's video output device connects internally to the display + /// device. In those cases, the DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL value is redundant. The caller should ignore + /// DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL and just process the embedded values, + /// DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED and DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED. + /// + /// An embedded display port or UDI is also known as an integrated display port or UDI. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ne-wingdi-displayconfig_video_output_technology typedef enum { + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO, + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO, + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS, + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL, + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL, + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE, + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_MIRACAST, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INDIRECT_WIRED, + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INDIRECT_VIRTUAL, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL, + // DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32 } ; + [PInvokeData("wingdi.h", MSDNShortId = "f8c2095a-d67e-42ed-b615-b5e0e0e0d507")] + public enum DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY : uint + { + /// Indicates a connector that is not one of the types that is indicated by the following enumerators in this enumeration. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER = unchecked((uint)-1), + + /// Indicates an HD15 (VGA) connector. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15 = 0, + + /// Indicates an S-video connector. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO, + + /// Indicates a composite video connector group. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO, + + /// Indicates a component video connector group. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO, + + /// Indicates a Digital Video Interface (DVI) connector. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI, + + /// Indicates a High-Definition Multimedia Interface (HDMI) connector. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI, + + /// Indicates a Low Voltage Differential Swing (LVDS) connector. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS, + + /// Indicates a Japanese D connector. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN, + + /// Indicates an SDI connector. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI, + + /// Indicates an external display port, which is a display port that connects externally to a display device. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL, + + /// Indicates an embedded display port that connects internally to a display device. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED, + + /// + /// Indicates an external Unified Display Interface (UDI), which is a UDI that connects externally to a display device. + /// + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL, + + /// Indicates an embedded UDI that connects internally to a display device. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED, + + /// Indicates a dongle cable that supports standard definition television (SDTV). + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE, + + /// Indicates that the VidPN target is a Miracast wireless display device. Supported starting in Windows 8.1. + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_MIRACAST, + + /// The displayconfig output technology indirect wired + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INDIRECT_WIRED, + + /// The displayconfig output technology indirect virtual + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INDIRECT_VIRTUAL, + + /// + /// Indicates that the video output device connects internally to a display device (for example, the internal connection in a + /// laptop computer). + /// + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL = 0x80000000, + } + + /// The DISPLAYCONFIG_2DREGION structure represents a point or an offset in a two-dimensional space. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_2dregion typedef struct DISPLAYCONFIG_2DREGION + // { UINT32 cx; UINT32 cy; } DISPLAYCONFIG_2DREGION; + [PInvokeData("wingdi.h", MSDNShortId = "ea306268-53fc-488b-afae-b8e9e5d09f2b")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct DISPLAYCONFIG_2DREGION + { + /// The horizontal component of the point or offset. + public uint cx; + + /// The vertical component of the point or offset. + public uint cy; + } + + /// The DISPLAYCONFIG_ADAPTER_NAME structure contains information about the display adapter. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_adapter_name typedef struct + // DISPLAYCONFIG_ADAPTER_NAME { DISPLAYCONFIG_DEVICE_INFO_HEADER header; WCHAR adapterDevicePath[128]; } DISPLAYCONFIG_ADAPTER_NAME; + [PInvokeData("wingdi.h", MSDNShortId = "248f325f-37ae-48f4-a758-ee78a3e3f0b8")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct DISPLAYCONFIG_ADAPTER_NAME + { + /// + /// A DISPLAYCONFIG_DEVICE_INFO_HEADER structure that contains information about the request for the adapter name. The caller + /// should set the type member of DISPLAYCONFIG_DEVICE_INFO_HEADER to DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME and the + /// adapterId member of DISPLAYCONFIG_DEVICE_INFO_HEADER to the adapter identifier of the adapter for which the caller + /// wants the name. For this request, the caller does not need to set the id member of DISPLAYCONFIG_DEVICE_INFO_HEADER. + /// The caller should set the size member of DISPLAYCONFIG_DEVICE_INFO_HEADER to at least the size of the + /// DISPLAYCONFIG_ADAPTER_NAME structure. + /// + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// + /// A NULL-terminated WCHAR string that is the device name for the adapter. This name can be used with SetupAPI.dll to obtain the + /// device name that is contained in the installation package. + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] + public string adapterDevicePath; + } + + /// The DISPLAYCONFIG_DESKTOP_IMAGE_INFO structure contains information about the image displayed on the desktop. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_desktop_image_info typedef struct + // DISPLAYCONFIG_DESKTOP_IMAGE_INFO { POINTL PathSourceSize; RECTL DesktopImageRegion; RECTL DesktopImageClip; } DISPLAYCONFIG_DESKTOP_IMAGE_INFO; + [PInvokeData("wingdi.h", MSDNShortId = "2DACA175-19BC-4192-A2FF-CB8AC7220B98")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct DISPLAYCONFIG_DESKTOP_IMAGE_INFO + { + /// A POINTL structure that specifies the size of the VidPn source surface that is being displayed on the monitor. + public Point PathSourceSize; + + /// + /// A RECTL structure that defines where the desktop image will be positioned within path source. Region must be completely + /// inside the bounds of the path source size. + /// + public RECT DesktopImageRegion; + + /// + /// A RECTL structure that defines which part of the desktop image for this clone group will be displayed on this path. This + /// currently must be set to the desktop size. + /// + public RECT DesktopImageClip; + } + + /// The DISPLAYCONFIG_DEVICE_INFO_HEADER structure contains display information about the device. + /// + /// The DisplayConfigGetDeviceInfo function uses the DISPLAYCONFIG_DEVICE_INFO_HEADER structure for retrieving display configuration + /// information about the device, and the DisplayConfigSetDeviceInfo function uses the DISPLAYCONFIG_DEVICE_INFO_HEADER structure for + /// setting display configuration information for the device. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_device_info_header typedef struct + // DISPLAYCONFIG_DEVICE_INFO_HEADER { DISPLAYCONFIG_DEVICE_INFO_TYPE type; UINT32 size; LUID adapterId; UINT32 id; } DISPLAYCONFIG_DEVICE_INFO_HEADER; + [PInvokeData("wingdi.h", MSDNShortId = "2fdfa54e-2a5f-448f-98e3-e51ce0acaeaf")] + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)] + public struct DISPLAYCONFIG_DEVICE_INFO_HEADER + { + /// + /// A DISPLAYCONFIG_DEVICE_INFO_TYPE enumerated value that determines the type of device information to retrieve or set. The + /// remainder of the packet for the retrieve or set operation follows immediately after the DISPLAYCONFIG_DEVICE_INFO_HEADER structure. + /// + public DISPLAYCONFIG_DEVICE_INFO_TYPE type; + + /// + /// The size, in bytes, of the device information that is retrieved or set. This size includes the size of the header and the + /// size of the additional data that follows the header. This device information depends on the request type. + /// + public uint size; + + /// A locally unique identifier (LUID) that identifies the adapter that the device information packet refers to. + public ulong adapterId; + + /// + /// The source or target identifier to get or set the device information for. The meaning of this identifier is related to the + /// type of information being requested. For example, in the case of DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, this is the + /// source identifier. + /// + public uint id; + } + + /// Undocumented. + [PInvokeData("wingdi.h")] + [StructLayout(LayoutKind.Sequential)] + public struct DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO + { + /// Undocumented. + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// Undocumented. + public DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_VALUE value; + + /// Undocumented. + public DISPLAYCONFIG_COLOR_ENCODING colorEncoding; + + /// Undocumented. + public uint bitsPerColorChannel; + } + + /// The DISPLAYCONFIG_MODE_INFO structure contains either source mode or target mode information. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_mode_info typedef struct + // DISPLAYCONFIG_MODE_INFO { DISPLAYCONFIG_MODE_INFO_TYPE infoType; UINT32 id; LUID adapterId; union { DISPLAYCONFIG_TARGET_MODE + // targetMode; DISPLAYCONFIG_SOURCE_MODE sourceMode; DISPLAYCONFIG_DESKTOP_IMAGE_INFO desktopImageInfo; } DUMMYUNIONNAME; } DISPLAYCONFIG_MODE_INFO; + [PInvokeData("wingdi.h", MSDNShortId = "39ffe49b-96d3-4d8b-94a7-01c388448b82")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)] + public struct DISPLAYCONFIG_MODE_INFO + { + /// + /// A value that indicates whether the DISPLAYCONFIG_MODE_INFO structure represents source or target mode information. If + /// infoType is DISPLAYCONFIG_MODE_INFO_TYPE_TARGET, the targetMode parameter value contains a valid + /// DISPLAYCONFIG_TARGET_MODE structure describing the specified target. If infoType is + /// DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE, the sourceMode parameter value contains a valid DISPLAYCONFIG_SOURCE_MODE structure + /// describing the specified source. + /// + public DISPLAYCONFIG_MODE_INFO_TYPE infoType; + + /// The source or target identifier on the specified adapter that this path relates to. + public uint id; + + /// The identifier of the adapter that this source or target mode information relates to. + public ulong adapterId; + + /// + /// A valid DISPLAYCONFIG_TARGET_MODE structure that describes the specified target only when infoType is DISPLAYCONFIG_MODE_INFO_TYPE_TARGET. + /// + public DISPLAYCONFIG_TARGET_MODE targetMode; + + /// + /// A valid DISPLAYCONFIG_SOURCE_MODE structure that describes the specified source only when infoType is DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE. + /// + public DISPLAYCONFIG_SOURCE_MODE sourceMode; + + /// + /// + /// A DISPLAYCONFIG_DESKTOP_IMAGE_INFO structure that describes information about the desktop image only when infoType is DISPLAYCONFIG_MODE_INFO_TYPE_. + /// + /// Supported starting in Windows 10. + /// + public DISPLAYCONFIG_DESKTOP_IMAGE_INFO desktopImageInfo; + } + + /// The DISPLAYCONFIG_PATH_INFO structure is used to describe a single path from a target to a source. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_path_info typedef struct + // DISPLAYCONFIG_PATH_INFO { DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo; DISPLAYCONFIG_PATH_TARGET_INFO targetInfo; UINT32 flags; } DISPLAYCONFIG_PATH_INFO; + [PInvokeData("wingdi.h", MSDNShortId = "e218c36d-60d5-42c8-9443-419a388a2b8d")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct DISPLAYCONFIG_PATH_INFO + { + /// A DISPLAYCONFIG_PATH_SOURCE_INFO structure that contains the source information for the path. + public DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo; + + /// A DISPLAYCONFIG_PATH_TARGET_INFO structure that contains the target information for the path. + public DISPLAYCONFIG_PATH_TARGET_INFO targetInfo; + + /// + /// A bitwise OR of flag values that indicates the state of the path. The following values are supported: + /// DISPLAYCONFIG_PATH_ACTIVE + /// + /// Set by QueryDisplayConfig to indicate that the path is active and part of the desktop. If this flag value is set, + /// SetDisplayConfig attempts to enable this path. + /// + /// DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE + /// Set by QueryDisplayConfig to indicate that the path supports the virtual mode. Supported starting in Windows 10. + /// + public uint flags; + } + + /// The DISPLAYCONFIG_PATH_SOURCE_INFO structure contains source information for a single path. + /// + /// A DISPLAYCONFIG_PATH_SOURCE_INFO structure is specified in the sourceInfo member of a DISPLAYCONFIG_PATH_INFO structure. + /// + /// A source corresponds to a surface on which the display adapter can render pixels. Each display adapter is capable of rendering to + /// x number of sources. What this means is how many desktops can be rendered for extend mode. This is typically 2. For example, + /// source 0 might be rendering pixels from 0,0 to 1024,768, and source 1 might be rendering pixels from 1025,0 to 2048, 768. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_path_source_info typedef struct + // DISPLAYCONFIG_PATH_SOURCE_INFO { LUID adapterId; UINT32 id; union { UINT32 modeInfoIdx; struct { UINT32 cloneGroupId : 16; UINT32 + // sourceModeInfoIdx : 16; } DUMMYSTRUCTNAME; } DUMMYUNIONNAME; UINT32 statusFlags; } DISPLAYCONFIG_PATH_SOURCE_INFO; + [PInvokeData("wingdi.h", MSDNShortId = "df43d20b-a55a-4bec-89a2-9ede03b4d6c5")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)] + public struct DISPLAYCONFIG_PATH_SOURCE_INFO + { + /// The identifier of the adapter that this source information relates to. + public ulong adapterId; + + /// The source identifier on the specified adapter that this path relates to. + public uint id; + + /// A union. + public Union union; + + /// + /// A bitwise OR of flag values that indicates the status of the source. The following values are supported: + /// DISPLAYCONFIG_SOURCE_IN_USE + /// This source is in use by at least one active path. + /// + public uint statusFlags; + + /// A union. + [StructLayout(LayoutKind.Explicit)] + public struct Union + { + /// + /// A valid index into the mode information table that contains the source mode information for this path only when + /// DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE is not set. If source mode information is not available, the value of + /// modeInfoIdx is DISPLAYCONFIG_PATH_MODE_IDX_INVALID. + /// + [FieldOffset(0)] + public uint modeInfoIdx; + + /// + /// + /// A valid identifier used to show which clone group the path is a member of only when + /// DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE is set. If this value is invalid, then it must be set to DISPLAYCONFIG_PATH_CLONE_GROUP_INVALID. + /// + /// + /// cloneGroupId is only used when the source mode index is not specified. Two such scenarios are when the source mode + /// info must be invalid because SDC_TOPOLOGY_SUPPLIED is used, and when SDC_USE_SUPPLIED_DISPLAY_CONFIG is used with paths + /// that do not have source mode info. The cloneGroupId will be used to indicate which paths are in a clone group, all + /// the paths with the same cloneGroupId value are considered in the same clone group. There is no requirement that + /// the clone group id’s have to be zero based or contiguous. Supported starting in Windows 10. + /// + /// + [FieldOffset(0)] + public ushort cloneGroupId; + + /// + /// A valid index into the mode array of the DISPLAYCONFIG_SOURCE_MODE entry that contains the source mode information for + /// this path only when DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE is set. If there is no entry for this in the mode array, the + /// value of sourceModeInfoIdx is DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID. Supported starting in Windows 10. + /// + [FieldOffset(2)] + public ushort sourceModeInfoIdx; + } + } + + /// The DISPLAYCONFIG_PATH_TARGET_INFO structure contains target information for a single path. + /// + /// A DISPLAYCONFIG_PATH_TARGET_INFO structure is specified in the targetInfo member of a DISPLAYCONFIG_PATH_INFO structure. + /// + /// A target corresponds to the number of possible video outputs on a display adapter. This number, however, does not equate to the + /// number of physical connectors on the display adapter. Each connector exposes a number of targets that includes backward + /// compatibility with older connector technology. For example, a DVI connector exposes a DVI target, as well as a VGA target. A + /// DisplayPort connector, which was introduced in 2006, exposes DisplayPort, HDMI, DVI, legacy TV, and VGA targets. + /// + /// The statusFlags member is set when you call the QueryDisplayConfig function. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_path_target_info typedef struct + // DISPLAYCONFIG_PATH_TARGET_INFO { LUID adapterId; UINT32 id; union { UINT32 modeInfoIdx; struct { UINT32 desktopModeInfoIdx : 16; + // UINT32 targetModeInfoIdx : 16; } DUMMYSTRUCTNAME; } DUMMYUNIONNAME; DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology; + // DISPLAYCONFIG_ROTATION rotation; DISPLAYCONFIG_SCALING scaling; DISPLAYCONFIG_RATIONAL refreshRate; + // DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering; BOOL targetAvailable; UINT32 statusFlags; } DISPLAYCONFIG_PATH_TARGET_INFO; + [PInvokeData("wingdi.h", MSDNShortId = "3dcdca96-7c5d-4e69-b7dd-8b5ccda25f6a")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)] + public struct DISPLAYCONFIG_PATH_TARGET_INFO + { + /// The identifier of the adapter that the path is on. + public ulong adapterId; + + /// The target identifier on the specified adapter that this path relates to. + public uint id; + + /// A union. + public Union union; + + /// + /// The target's connector type. For a list of possible values, see the DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY enumerated type. + /// + public DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology; + + /// + /// A value that specifies the rotation of the target. For a list of possible values, see the DISPLAYCONFIG_ROTATION enumerated type. + /// + public DISPLAYCONFIG_ROTATION rotation; + + /// + /// A value that specifies how the source image is scaled to the target. For a list of possible values, see the + /// DISPLAYCONFIG_SCALING enumerated type. For more information about scaling, see Scaling the Desktop Image. + /// + public DISPLAYCONFIG_SCALING scaling; + + /// + /// A DISPLAYCONFIG_RATIONAL structure that specifies the refresh rate of the target. If the caller specifies target mode + /// information, the operating system will instead use the refresh rate that is stored in the vSyncFreq member of the + /// DISPLAYCONFIG_VIDEO_SIGNAL_INFO structure. In this case, the caller specifies this value in the targetVideoSignalInfo + /// member of the DISPLAYCONFIG_TARGET_MODE structure. A refresh rate with both the numerator and denominator set to zero + /// indicates that the caller does not specify a refresh rate and the operating system should use the most optimal refresh rate + /// available. For this case, in a call to the SetDisplayConfig function, the caller must set the scanLineOrdering member + /// to the DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED value; otherwise, SetDisplayConfig fails. + /// + public DISPLAYCONFIG_RATIONAL refreshRate; + + /// + /// A value that specifies the scan-line ordering of the output on the target. For a list of possible values, see the + /// DISPLAYCONFIG_SCANLINE_ORDERING enumerated type. If the caller specifies target mode information, the operating system will + /// instead use the scan-line ordering that is stored in the scanLineOrdering member of the + /// DISPLAYCONFIG_VIDEO_SIGNAL_INFO structure. In this case, the caller specifies this value in the targetVideoSignalInfo + /// member of the DISPLAYCONFIG_TARGET_MODE structure. + /// + public DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering; + + /// + /// A Boolean value that specifies whether the target is available. TRUE indicates that the target is available. + /// + /// Because the asynchronous nature of display topology changes when a monitor is removed, a path might still be marked as active + /// even though the monitor has been removed. In such a case, targetAvailable could be FALSE for an active path. + /// This is typically a transient situation that will change after the operating system takes action on the monitor removal. + /// + /// + [MarshalAs(UnmanagedType.Bool)] public bool targetAvailable; + + /// + /// A bitwise OR of flag values that indicates the status of the target. The following values are supported: + /// DISPLAYCONFIG_TARGET_IN_USE + /// Target is in use on an active path. + /// DISPLAYCONFIG_TARGET_FORCIBLE + /// The output can be forced on this target even if a monitor is not detected. + /// DISPLAYCONFIG_TARGET_FORCED_AVAILABILITY_BOOT + /// Output is currently being forced in a boot-persistent manner. + /// DISPLAYCONFIG_TARGET_FORCED_AVAILABILITY_PATH + /// Output is currently being forced in a path-persistent manner. + /// DISPLAYCONFIG_TARGET_FORCED_AVAILABILITY_SYSTEM + /// Output is currently being forced in a non-persistent manner. + /// + public uint statusFlags; + + /// A union. + [StructLayout(LayoutKind.Explicit)] + public struct Union + { + /// + /// A valid index into the mode information table that contains the target mode information for this path only when + /// DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE is not set. If target mode information is not available, the value of + /// modeInfoIdx is DISPLAYCONFIG_PATH_MODE_IDX_INVALID. + /// + [FieldOffset(0)] + public uint modeInfoIdx; + + /// + /// A valid index into the mode array of the DISPLAYCONFIG_DESKTOP_IMAGE_INFO entry that contains the desktop mode + /// information for this path only when DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE is set. If there is no entry for this in the + /// mode array, the value of desktopModeInfoIdx is DISPLAYCONFIG_PATH_DESKTOP_IMAGE_IDX_INVALID. Supported starting in + /// Windows 10. + /// + [FieldOffset(0)] + public ushort desktopModeInfoIdx; + + /// + /// A valid index into the mode array of the DISPLAYCONFIG_TARGET_MODE entry that contains the target mode information for + /// this path only when DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE is set. If there is no entry for this in the mode array, the + /// value of targetModeInfoIdx is DISPLAYCONFIG_PATH_TARGET_MODE_IDX_INVALID. Supported starting in Windows 10. + /// + [FieldOffset(2)] + public ushort targetModeInfoIdx; + } + } + + /// + /// The DISPLAYCONFIG_RATIONAL structure describes a fractional value that represents vertical and horizontal frequencies of a video + /// mode (that is, vertical sync and horizontal sync). + /// + /// + /// A DISPLAYCONFIG_RATIONAL structure is specified in members of the DISPLAYCONFIG_PATH_TARGET_INFO and + /// DISPLAYCONFIG_VIDEO_SIGNAL_INFO structures. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_rational typedef struct DISPLAYCONFIG_RATIONAL + // { UINT32 Numerator; UINT32 Denominator; } DISPLAYCONFIG_RATIONAL; + [PInvokeData("wingdi.h", MSDNShortId = "1f2f25f7-5ea1-46f4-ad9f-c50c367bb600")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct DISPLAYCONFIG_RATIONAL + { + /// The numerator of the frequency fraction. + public uint Numerator; + + /// The denominator of the frequency fraction. + public uint Denominator; + } + + /// Undocumented. + [PInvokeData("wingdi.h")] + [StructLayout(LayoutKind.Sequential)] + public struct DISPLAYCONFIG_SDR_WHITE_LEVEL + { + /// Undocumented. + private DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// + /// SDRWhiteLevel represents a multiplier for standard SDR white peak value i.e. 80 nits represented as fixed point. To get value + /// in nits use the following conversion SDRWhiteLevel in nits = (SDRWhiteLevel / 1000 ) * 80 + /// + public uint SDRWhiteLevel; + } + + /// Undocumented. + [PInvokeData("wingdi.h")] + [StructLayout(LayoutKind.Sequential)] + public struct DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE + { + /// Undocumented. + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// Undocumented. + public DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE_VALUE value; + } + + /// The DISPLAYCONFIG_SET_TARGET_PERSISTENCE structure contains information about setting the display. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_set_target_persistence typedef struct + // DISPLAYCONFIG_SET_TARGET_PERSISTENCE { DISPLAYCONFIG_DEVICE_INFO_HEADER header; union { struct { UINT32 bootPersistenceOn : 1; + // UINT32 reserved : 31; } DUMMYSTRUCTNAME; UINT32 value; } DUMMYUNIONNAME; } DISPLAYCONFIG_SET_TARGET_PERSISTENCE; + [PInvokeData("wingdi.h", MSDNShortId = "4798a1e1-8685-40c2-917a-0ee071bc780c")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct DISPLAYCONFIG_SET_TARGET_PERSISTENCE + { + /// + /// A DISPLAYCONFIG_DEVICE_INFO_HEADER structure that contains information for setting the target persistence. The type + /// member of DISPLAYCONFIG_DEVICE_INFO_HEADER is set to DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE. + /// DISPLAYCONFIG_DEVICE_INFO_HEADER also contains the adapter and target identifiers of the target to set the persistence for. + /// The size member of DISPLAYCONFIG_DEVICE_INFO_HEADER is set to at least the size of the + /// DISPLAYCONFIG_SET_TARGET_PERSISTENCE structure. + /// + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// + /// A member in the union that DISPLAYCONFIG_SET_TARGET_PERSISTENCE contains that can hold a 32-bit value that identifies + /// information about setting the display. + /// + public DISPLAYCONFIG_SET_TARGET_PERSISTENCE_VALUE value; + } + + /// The DISPLAYCONFIG_SOURCE_DEVICE_NAME structure contains the GDI device name for the source or view. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_source_device_name typedef struct + // DISPLAYCONFIG_SOURCE_DEVICE_NAME { DISPLAYCONFIG_DEVICE_INFO_HEADER header; WCHAR viewGdiDeviceName[CCHDEVICENAME]; } DISPLAYCONFIG_SOURCE_DEVICE_NAME; + [PInvokeData("wingdi.h", MSDNShortId = "92813ffc-1915-4f26-afb1-936bf76f7844")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct DISPLAYCONFIG_SOURCE_DEVICE_NAME + { + /// + /// A DISPLAYCONFIG_DEVICE_INFO_HEADER structure that contains information about the request for the source device name. The + /// caller should set the type member of DISPLAYCONFIG_DEVICE_INFO_HEADER to DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME and + /// the adapterId and id members of DISPLAYCONFIG_DEVICE_INFO_HEADER to the source for which the caller wants the + /// source device name. The caller should set the size member of DISPLAYCONFIG_DEVICE_INFO_HEADER to at least the size of + /// the DISPLAYCONFIG_SOURCE_DEVICE_NAME structure. + /// + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// + /// A NULL-terminated WCHAR string that is the GDI device name for the source, or view. This name can be used in a call to + /// EnumDisplaySettings to obtain a list of available modes for the specified source. + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string viewGdiDeviceName; + } + + /// The DISPLAYCONFIG_SOURCE_MODE structure represents a point or an offset in a two-dimensional space. + /// + /// + /// The arrangement of source surfaces on the desktop is controlled by the position member, which specifies the position in + /// desktop coordinates of the upper-left corner of the source surface. The source surface that is positioned at (0, 0) is considered + /// the primary. GDI has strict rules about how the source surfaces can be arranged in the desktop space. For example, there cannot + /// be any gaps between source surfaces, and there can be no overlaps. + /// + /// + /// The SetDisplayConfig function attempts to rearrange source surfaces in order to enforce these layout rules. The caller must make + /// every effort to lay out the source surfaces correctly because GDI rearranges the sources in an undefined manner to enforce the + /// layout rules. The resultant layout may not be what the caller wanted to achieve. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_source_mode typedef struct + // DISPLAYCONFIG_SOURCE_MODE { UINT32 width; UINT32 height; DISPLAYCONFIG_PIXELFORMAT pixelFormat; POINTL position; } DISPLAYCONFIG_SOURCE_MODE; + [PInvokeData("wingdi.h", MSDNShortId = "413d63e5-da9d-4906-80a9-049da6e85275")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct DISPLAYCONFIG_SOURCE_MODE + { + /// The width in pixels of the source mode. + public uint width; + + /// The height in pixels of the source mode. + public uint height; + + /// A value from the DISPLAYCONFIG_PIXELFORMAT enumeration that specifies the pixel format of the source mode. + public DISPLAYCONFIG_PIXELFORMAT pixelFormat; + + /// + /// A POINTL structure that specifies the position in the desktop coordinate space of the upper-left corner of this source + /// surface. The source surface that is located at (0, 0) is always the primary source surface. + /// + public Point position; + } + + /// + /// The DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION structure contains information on the state of virtual resolution support for the monitor. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_support_virtual_resolution typedef struct + // DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION { DISPLAYCONFIG_DEVICE_INFO_HEADER header; union { struct { UINT32 + // disableMonitorVirtualResolution : 1; UINT32 reserved : 31; } DUMMYSTRUCTNAME; UINT32 value; } DUMMYSTRUCTNAME; } DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION; + [PInvokeData("wingdi.h", MSDNShortId = "D9208D00-F437-4B2E-8C39-044F75088659")] + [StructLayout(LayoutKind.Sequential)] + public struct DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION + { + /// + /// A DISPLAYCONFIG_DEVICE_INFO_HEADER structure that holds information on the type, size, adapterID, and ID of the target the + /// monitor is connected to. + /// + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// Reflects the value of disableMonitorVirtualResolution in cases where debugging is utilized. + public DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION_VALUE value; + } + + /// Specifies base output technology info for a given target ID. + /// + /// For a Miracast display device, a call to the DisplayConfigGetDeviceInfo function always returns a value of + /// DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY. DISPLAYCONFIG_OUTPUT_TECHNOLOGY_MIRACAST, regardless of what the Miracast sink + /// reports as the connector type. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_target_base_type typedef struct + // DISPLAYCONFIG_TARGET_BASE_TYPE { DISPLAYCONFIG_DEVICE_INFO_HEADER header; DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY + // baseOutputTechnology; } DISPLAYCONFIG_TARGET_BASE_TYPE; + [PInvokeData("wingdi.h", MSDNShortId = "7916E714-9A3C-4682-AC08-9B6EE222D8B7")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct DISPLAYCONFIG_TARGET_BASE_TYPE + { + /// + /// + /// A DISPLAYCONFIG_DEVICE_INFO_HEADER structure that contains info about the request for the target device name. The caller + /// should set the type member of DISPLAYCONFIG_DEVICE_INFO_HEADER to + /// DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE and the adapterId and id members of + /// DISPLAYCONFIG_DEVICE_INFO_HEADER to the target for which the caller wants the target device name. + /// + /// + /// The caller should set the size member of DISPLAYCONFIG_DEVICE_INFO_HEADER to at least the size of the + /// DISPLAYCONFIG_TARGET_BASE_TYPE structure. + /// + /// + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// + /// The base output technology, given as a constant value of the DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY enumeration, of the + /// adapter and the target specified by the header member. See Remarks. + /// + public DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY baseOutputTechnology; + } + + /// The DISPLAYCONFIG_TARGET_DEVICE_NAME structure contains information about the target. + /// + /// + /// Extended display identification data (EDID) is a set of data that is provided by a display to describe its capabilities to a + /// graphics adapter. EDID data allows a computer to detect the type of monitor that is connected to it. EDID data includes the + /// manufacturer name, the product type, the timings that are supported by the display, the display size, as well as other display + /// characteristics. EDID is defined by a standard published by the Video Electronics Standards Association (VESA). + /// + /// + /// A named device object has a path and name of the form \Device\DeviceName. This is known as the device name of the device object. + /// + /// + /// If an application calls the DisplayConfigGetDeviceInfo function to obtain the monitor name and DisplayConfigGetDeviceInfo + /// either cannot get the monitor name or the target is forced without a monitor connected, the string in the + /// monitorFriendlyDeviceName member of the DISPLAYCONFIG_TARGET_DEVICE_NAME structure is a NULL string and none of the + /// bit-field flags in the DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS structure are set. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_target_device_name typedef struct + // DISPLAYCONFIG_TARGET_DEVICE_NAME { DISPLAYCONFIG_DEVICE_INFO_HEADER header; DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS flags; + // DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology; UINT16 edidManufactureId; UINT16 edidProductCodeId; UINT32 + // connectorInstance; WCHAR monitorFriendlyDeviceName[64]; WCHAR monitorDevicePath[128]; } DISPLAYCONFIG_TARGET_DEVICE_NAME; + [PInvokeData("wingdi.h", MSDNShortId = "85507b69-8ce0-4f39-a4d3-7d67f515b451")] + // [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct DISPLAYCONFIG_TARGET_DEVICE_NAME{public + // DISPLAYCONFIG_DEVICE_INFO_HEADER header; public DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS flags; public + // DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology; public ushort edidManufactureId; public ushort edidProductCodeId; public + // uint connectorInstance; public ushort monitorFriendlyDeviceName[64]; public ushort monitorDevicePath[128]; public ; public + // DISPLAYCONFIG_TARGET_DEVICE_NAME; } + [StructLayout(LayoutKind.Sequential, Pack = 2, CharSet = CharSet.Unicode)] + public struct DISPLAYCONFIG_TARGET_DEVICE_NAME + { + /// + /// A DISPLAYCONFIG_DEVICE_INFO_HEADER structure that contains information about the request for the target device name. The + /// caller should set the type member of DISPLAYCONFIG_DEVICE_INFO_HEADER to DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME and + /// the adapterId and id members of DISPLAYCONFIG_DEVICE_INFO_HEADER to the target for which the caller wants the + /// target device name. The caller should set the size member of DISPLAYCONFIG_DEVICE_INFO_HEADER to at least the size of + /// the DISPLAYCONFIG_TARGET_DEVICE_NAME structure. + /// + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// + /// A DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS structure that identifies, in bit-field flags, information about the target. + /// + public DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS flags; + + /// A value from the DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY enumeration that specifies the target's connector type. + public DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology; + + /// + /// The manufacture identifier from the monitor extended display identification data (EDID). This member is set only when the + /// edidIdsValid bit-field is set in the flags member. + /// + public ushort edidManufactureId; + + /// + /// The product code from the monitor EDID. This member is set only when the edidIdsValid bit-field is set in the + /// flags member. + /// + public ushort edidProductCodeId; + + /// + /// The one-based instance number of this particular target only when the adapter has multiple targets of this type. The + /// connector instance is a consecutive one-based number that is unique within each adapter. If this is the only target of this + /// type on the adapter, this value is zero. + /// + public uint connectorInstance; + + /// + /// A NULL-terminated WCHAR string that is the device name for the monitor. This name can be used with SetupAPI.dll to obtain the + /// device name that is contained in the installation package. + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] + public string monitorFriendlyDeviceName; + + /// + /// A NULL-terminated WCHAR string that is the path to the device name for the monitor. This path can be used with SetupAPI.dll + /// to obtain the device name that is contained in the installation package. + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] + public string monitorDevicePath; + } + + /// The DISPLAYCONFIG_TARGET_MODE structure describes a display path target mode. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_target_mode typedef struct + // DISPLAYCONFIG_TARGET_MODE { DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo; } DISPLAYCONFIG_TARGET_MODE; + [PInvokeData("wingdi.h", MSDNShortId = "c81768f0-67d3-4ddd-94c8-013b1e4cf83e")] + [StructLayout(LayoutKind.Sequential)] + public struct DISPLAYCONFIG_TARGET_MODE + { + /// A DISPLAYCONFIG_VIDEO_SIGNAL_INFO structure that contains a detailed description of the current target mode. + public DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo; + } + + /// The DISPLAYCONFIG_TARGET_PREFERRED_MODE structure contains information about the preferred mode of a display. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_target_preferred_mode typedef struct + // DISPLAYCONFIG_TARGET_PREFERRED_MODE { DISPLAYCONFIG_DEVICE_INFO_HEADER header; UINT32 width; UINT32 height; + // DISPLAYCONFIG_TARGET_MODE targetMode; } DISPLAYCONFIG_TARGET_PREFERRED_MODE; + [PInvokeData("wingdi.h", MSDNShortId = "1a4926ca-36d2-466c-b3d2-b59d34a89ee6")] + [StructLayout(LayoutKind.Sequential)] + public struct DISPLAYCONFIG_TARGET_PREFERRED_MODE + { + /// + /// A DISPLAYCONFIG_DEVICE_INFO_HEADER structure that contains information about the request for the target preferred mode. The + /// caller should set the type member of DISPLAYCONFIG_DEVICE_INFO_HEADER to + /// DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE and the adapterId and id members of + /// DISPLAYCONFIG_DEVICE_INFO_HEADER to the target for which the caller wants the preferred mode. The caller should set the + /// size member of DISPLAYCONFIG_DEVICE_INFO_HEADER to at least the size of the DISPLAYCONFIG_TARGET_PREFERRED_MODE structure. + /// + public DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + /// + /// The width in pixels of the best mode for the monitor that is connected to the target that the targetMode member specifies. + /// + public uint width; + + /// + /// The height in pixels of the best mode for the monitor that is connected to the target that the targetMode member specifies. + /// + public uint height; + + private uint aligner; + + /// + /// A DISPLAYCONFIG_TARGET_MODE structure that describes the best target mode for the monitor that is connected to the specified target. + /// + public DISPLAYCONFIG_TARGET_MODE targetMode; + } + + /// The DISPLAYCONFIG_VIDEO_SIGNAL_INFO structure contains information about the video signal for a display. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-displayconfig_video_signal_info typedef struct + // DISPLAYCONFIG_VIDEO_SIGNAL_INFO { UINT64 pixelRate; DISPLAYCONFIG_RATIONAL hSyncFreq; DISPLAYCONFIG_RATIONAL vSyncFreq; + // DISPLAYCONFIG_2DREGION activeSize; DISPLAYCONFIG_2DREGION totalSize; union { struct { UINT32 videoStandard : 16; UINT32 + // vSyncFreqDivider : 6; UINT32 reserved : 10; } AdditionalSignalInfo; UINT32 videoStandard; } DUMMYUNIONNAME; + // DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering; } DISPLAYCONFIG_VIDEO_SIGNAL_INFO; + [PInvokeData("wingdi.h", MSDNShortId = "960089fe-dbb7-41a1-af73-0002cfce6da2")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)] + public struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO + { + /// The pixel clock rate. + public ulong pixelRate; + + /// A DISPLAYCONFIG_RATIONAL structure that represents horizontal sync. + public DISPLAYCONFIG_RATIONAL hSyncFreq; + + /// A DISPLAYCONFIG_RATIONAL structure that represents vertical sync. + public DISPLAYCONFIG_RATIONAL vSyncFreq; + + /// + /// A DISPLAYCONFIG_2DREGION structure that specifies the width and height (in pixels) of the active portion of the video signal. + /// + public DISPLAYCONFIG_2DREGION activeSize; + + /// A DISPLAYCONFIG_2DREGION structure that specifies the width and height (in pixels) of the entire video signal. + public DISPLAYCONFIG_2DREGION totalSize; + + /// + /// The video standard (if any) that defines the video signal. For a list of possible values, see the + /// D3DKMDT_VIDEO_SIGNAL_STANDARD enumerated type. + /// + public D3DKMDT_VIDEO_SIGNAL_STANDARD videoStandard; + + /// The ratio of the VSync rate of a monitor that displays through a Miracast connected session to the VSync rate of the Miracast sink. + /// To avoid visual artifacts, the VSync rate of the display monitor that's connected to the Miracast sink must be an integer multiple of the VSync rate of the Miracast sink. The display miniport driver reports the latter rate to the operating system as the refresh rate of the desktop present path. + /// The operating system fails any attempt by the driver to add a target mode that results in a Miracast target having a VSync rate below 23.9 Hz. + /// For a non-Miracast target, the driver should set vSyncFreqDivider to zero. + /// Supported starting with Windows 8.1. + public ushort vSyncFreqDivider; + + /// + /// The scan-line ordering (for example, progressive or interlaced) of the video signal. For a list of possible values, see the + /// DISPLAYCONFIG_SCANLINE_ORDERING enumerated type. + /// + public DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering; + } + + /// + /// The D3DKMDT_VIDEO_SIGNAL_STANDARD enumeration contains constants that represent video signal standards. + /// + /// + /// The SignalInfo member of the D3DKMDT_VIDPN_TARGET_MODE structure is a D3DKMDT_VIDEO_SIGNAL_MODE structure.The VideoStandard member of the D3DKMDT_VIDEO_SIGNAL_MODE structure is a D3DKMDT_VIDEO_SIGNAL_STANDARD value. + /// + // https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/d3dkmdt/ne-d3dkmdt-_d3dkmdt_video_signal_standard + // typedef enum _D3DKMDT_VIDEO_SIGNAL_STANDARD { D3DKMDT_VSS_UNINITIALIZED, D3DKMDT_VSS_VESA_DMT, D3DKMDT_VSS_VESA_GTF, D3DKMDT_VSS_VESA_CVT, D3DKMDT_VSS_IBM, D3DKMDT_VSS_APPLE, D3DKMDT_VSS_NTSC_M, D3DKMDT_VSS_NTSC_J, D3DKMDT_VSS_NTSC_443, D3DKMDT_VSS_PAL_B, D3DKMDT_VSS_PAL_B1, D3DKMDT_VSS_PAL_G, D3DKMDT_VSS_PAL_H, D3DKMDT_VSS_PAL_I, D3DKMDT_VSS_PAL_D, D3DKMDT_VSS_PAL_N, D3DKMDT_VSS_PAL_NC, D3DKMDT_VSS_SECAM_B, D3DKMDT_VSS_SECAM_D, D3DKMDT_VSS_SECAM_G, D3DKMDT_VSS_SECAM_H, D3DKMDT_VSS_SECAM_K, D3DKMDT_VSS_SECAM_K1, D3DKMDT_VSS_SECAM_L, D3DKMDT_VSS_SECAM_L1, D3DKMDT_VSS_EIA_861, D3DKMDT_VSS_EIA_861A, D3DKMDT_VSS_EIA_861B, D3DKMDT_VSS_PAL_K, D3DKMDT_VSS_PAL_K1, D3DKMDT_VSS_PAL_L, D3DKMDT_VSS_PAL_M, D3DKMDT_VSS_OTHER } D3DKMDT_VIDEO_SIGNAL_STANDARD; + [PInvokeData("d3dkmdt.h", MSDNShortId = "bb129e02-ae01-4bbc-a81f-809f1a27060c")] + public enum D3DKMDT_VIDEO_SIGNAL_STANDARD : ushort + { + /// + /// Indicates that a variable of type D3DKMDT_VIDEO_SIGNAL_STANDARD has not yet been assigned a meaningful value. + /// + D3DKMDT_VSS_UNINITIALIZED = 0, + /// Represents the Video Electronics Standards Association (VESA) Display Monitor Timing (DMT) standard. + D3DKMDT_VSS_VESA_DMT, + /// Represents the VESA Generalized Timing Formula (GTF) standard. + D3DKMDT_VSS_VESA_GTF, + /// Represents the VESA Coordinated Video Timing (CVT) standard. + D3DKMDT_VSS_VESA_CVT, + /// Represents the IBM standard. + D3DKMDT_VSS_IBM, + /// Represents the Apple standard. + D3DKMDT_VSS_APPLE, + /// Represents the National Television Standards Committee (NTSC) standard. + D3DKMDT_VSS_NTSC_M, + /// Represents the NTSC standard. + D3DKMDT_VSS_NTSC_J, + /// Represents the NTSC standard. + D3DKMDT_VSS_NTSC_443, + /// Represents the Phase Alteration Line (PAL) standard. + D3DKMDT_VSS_PAL_B, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_B1, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_G, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_H, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_I, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_D, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_N, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_NC, + /// Represents the Systeme Electronic Pour Couleur Avec Memoire (SECAM) standard. + D3DKMDT_VSS_SECAM_B, + /// Represents the SECAM standard. + D3DKMDT_VSS_SECAM_D, + /// Represents the SECAM standard. + D3DKMDT_VSS_SECAM_G, + /// Represents the SECAM standard. + D3DKMDT_VSS_SECAM_H, + /// Represents the SECAM standard. + D3DKMDT_VSS_SECAM_K, + /// Represents the SECAM standard. + D3DKMDT_VSS_SECAM_K1, + /// Represents the SECAM standard. + D3DKMDT_VSS_SECAM_L, + /// Represents the SECAM standard. + D3DKMDT_VSS_SECAM_L1, + /// Represents the Electronics Industries Association (EIA) standard. + D3DKMDT_VSS_EIA_861, + /// Represents the EIA standard. + D3DKMDT_VSS_EIA_861A, + /// Represents the EIA standard. + D3DKMDT_VSS_EIA_861B, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_K, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_K1, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_L, + /// Represents the PAL standard. + D3DKMDT_VSS_PAL_M, + /// + /// Represents any video standard other than those represented by the previous constants in this enumeration. + /// + D3DKMDT_VSS_OTHER = 255, + } + } +} \ No newline at end of file diff --git a/PInvoke/User32.Gdi/WinUser.Display.cs b/PInvoke/User32.Gdi/WinUser.Display.cs new file mode 100644 index 00000000..f9eb4727 --- /dev/null +++ b/PInvoke/User32.Gdi/WinUser.Display.cs @@ -0,0 +1,1096 @@ +using System; +using System.Runtime.InteropServices; +using Vanara.Extensions; +using Vanara.InteropServices; +using static Vanara.PInvoke.Gdi32; + +namespace Vanara.PInvoke +{ + public static partial class User32_Gdi + { + /// The type of information to retrieve. + [PInvokeData("wingdi.h", MSDNShortId = "5ec7f521-28b5-4922-a3fc-aa4433de69e0")] + [Flags] + public enum QDC + { + /// The caller requests the table sizes to hold all the possible path combinations. + QDC_ALL_PATHS = 0x00000001, + + /// The caller requests the table sizes to hold only active paths. + QDC_ONLY_ACTIVE_PATHS = 0x00000002, + + /// + /// The caller requests the table sizes to hold the active paths as defined in the persistence database for the currently + /// connected monitors. + /// + QDC_DATABASE_CURRENT = 0x00000004, + + /// Undocumented. + QDC_VIRTUAL_MODE_AWARE = 0x00000010, + + /// Undocumented. + QDC_INCLUDE_HMD = 0x00000020, + } + + /// Flag values that indicates the behavior of SetDisplayConfig. + [PInvokeData("wingdi.h", MSDNShortId = "9f649fa0-ffb2-44c6-9a66-049f888e3b04")] + [Flags] + public enum SDC + { + /// The caller requests the last internal configuration from the persistence database. + SDC_TOPOLOGY_INTERNAL = 0x00000001, + + /// The caller requests the last clone configuration from the persistence database. + SDC_TOPOLOGY_CLONE = 0x00000002, + + /// The caller requests the last extended configuration from the persistence database. + SDC_TOPOLOGY_EXTEND = 0x00000004, + + /// The caller requests the last external configuration from the persistence database. + SDC_TOPOLOGY_EXTERNAL = 0x00000008, + + /// + /// The caller provides the path data so the function only queries the persistence database to find and use the source and target mode. + /// + SDC_TOPOLOGY_SUPPLIED = 0x00000010, + + /// + /// The caller requests a combination of all four SDC_TOPOLOGY_XXX configurations. This value informs the API to set the last + /// known display configuration for the current connected monitors. + /// + SDC_USE_DATABASE_CURRENT = SDC_TOPOLOGY_INTERNAL | SDC_TOPOLOGY_CLONE | SDC_TOPOLOGY_EXTEND | SDC_TOPOLOGY_EXTERNAL, + + /// + /// The topology, source, and target mode information that are supplied in the pathArray and the modeInfoArray parameters are + /// used, rather than looking up the configuration in the database. + /// + SDC_USE_SUPPLIED_DISPLAY_CONFIG = 0x00000020, + + /// + /// The system tests for the requested topology, source, and target mode information to determine whether it can be set. + /// + SDC_VALIDATE = 0x00000040, + + /// The resulting topology, source, and target mode is set. + SDC_APPLY = 0x00000080, + + /// + /// A modifier to the SDC_APPLY flag. This causes the change mode to be forced all the way down to the driver for each active display. + /// + SDC_NO_OPTIMIZATION = 0x00000100, + + /// The resulting topology, source, and target mode are saved to the database. + SDC_SAVE_TO_DATABASE = 0x00000200, + + /// + /// If required, the function can modify the specified source and target mode information in order to create a functional display + /// path set. + /// + SDC_ALLOW_CHANGES = 0x00000400, + + /// + /// When the function processes a SDC_TOPOLOGY_XXX request, it can force path persistence on a target to satisfy the request if + /// necessary. For information about the other flags that this flag can be combined with, see the following list. + /// + SDC_PATH_PERSIST_IF_REQUIRED = 0x00000800, + + /// + /// The caller requests that the driver is given an opportunity to update the GDI mode list while SetDisplayConfig sets the new + /// display configuration. This flag value is only valid when the SDC_USE_SUPPLIED_DISPLAY_CONFIG and SDC_APPLY flag values are + /// also specified. + /// + SDC_FORCE_MODE_ENUMERATION = 0x00001000, + + /// + /// A modifier to the SDC_TOPOLOGY_SUPPLIED flag that indicates that SetDisplayConfig should ignore the path order of the + /// supplied topology when searching the database. When this flag is set, the topology set is the most recent topology that + /// contains all the paths regardless of the path order. + /// + SDC_ALLOW_PATH_ORDER_CHANGES = 0x00002000, + + /// Undocumented. + SDC_VIRTUAL_MODE_AWARE = 0x00008000, + } + + /// The DisplayConfigGetDeviceInfo function retrieves display configuration information about the device. + /// + /// A pointer to a DISPLAYCONFIG_DEVICE_INFO_HEADER structure. This structure contains information about the request, which includes + /// the packet type in the type member. The type and size of additional data that DisplayConfigGetDeviceInfo returns + /// after the header structure depend on the packet type. + /// + /// + /// The function returns one of the following return codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_SUCCESS + /// The function succeeded. + /// + /// + /// ERROR_INVALID_PARAMETER + /// The combination of parameters and flags specified are invalid. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The system is not running a graphics driver that was written according to the Windows Display Driver Model (WDDM). The function + /// is only supported on a system with a WDDM driver running. + /// + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// The caller does not have access to the console session. This error occurs if the calling process does not have access to the + /// current desktop or is running on a remote session. + /// + /// + /// + /// ERROR_INSUFFICIENT_BUFFER + /// The size of the packet that the caller passes is not big enough for the information that the caller requests. + /// + /// + /// ERROR_GEN_FAILURE + /// An unspecified error occurred. + /// + /// + /// + /// + /// + /// Use the DisplayConfigGetDeviceInfo function to obtain additional information about a source or target for an adapter, such + /// as the display name, the preferred display mode, and source device name. + /// + /// + /// The caller can call DisplayConfigGetDeviceInfo to obtain more friendly names to display in the user interface. The caller + /// can obtain names for the adapter, the source, and the target. The caller can also call DisplayConfigGetDeviceInfo to + /// obtain the best resolution of the connected display device. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-displayconfiggetdeviceinfo LONG + // DisplayConfigGetDeviceInfo( DISPLAYCONFIG_DEVICE_INFO_HEADER *requestPacket ); + [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("winuser.h", MSDNShortId = "249dcb1a-4ce3-4478-8331-fb81e91313b0")] + public static extern Win32Error DisplayConfigGetDeviceInfo(IntPtr requestPacket); + + /// The DisplayConfigGetDeviceInfo function retrieves display configuration information about the device. + /// The type of structure to return. This must match the type supported by . + /// + /// A locally unique identifier (LUID) that identifies the adapter that the device information packet refers to. + /// + /// + /// The source or target identifier to get or set the device information for. The meaning of this identifier is related to the type + /// of information being requested. For example, in the case of DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, this is the source identifier. + /// + /// + /// A DISPLAYCONFIG_DEVICE_INFO_TYPE enumerated value that determines the type of device information to retrieve or set. The + /// remainder of the packet for the retrieve or set operation follows immediately after the DISPLAYCONFIG_DEVICE_INFO_HEADER + /// structure. Leave this value as the default (0) to have the value inferred from . + /// + /// The value of type for the information provided. + /// Request type does not match type param value. + public static T DisplayConfigGetDeviceInfo(ulong adapterId, uint id, DISPLAYCONFIG_DEVICE_INFO_TYPE type = 0) where T : struct + { + if (type == 0) + { + if (!CorrespondingTypeAttribute.CanGet(out type)) throw new ArgumentException("Unable to find enum value matching supplied type param."); + } + else if (!CorrespondingTypeAttribute.CanGet(type, typeof(T))) throw new ArgumentException("Request type does not match type param value."); + var hdr = new DISPLAYCONFIG_DEVICE_INFO_HEADER { size = (uint)Marshal.SizeOf(typeof(T)), type = type, adapterId = adapterId, id = id }; + var mem = new SafeHGlobalHandle((int)hdr.size); + mem.Zero(); + Marshal.StructureToPtr(hdr, (IntPtr)mem, false); + var hdr2 = mem.ToStructure(); + var err = DisplayConfigGetDeviceInfo((IntPtr)mem); + err.ThrowIfFailed(); + return mem.ToStructure(); + } + + /// The DisplayConfigSetDeviceInfo function sets the properties of a target. + /// + /// A pointer to a DISPLAYCONFIG_DEVICE_INFO_HEADER structure that contains information to set for the device. The type and size of + /// additional data that DisplayConfigSetDeviceInfo uses for the configuration comes after the header structure. This + /// additional data depends on the packet type, as specified by the type member of DISPLAYCONFIG_DEVICE_INFO_HEADER. For + /// example, if the caller wants to change the boot persistence, that caller allocates and fills a + /// DISPLAYCONFIG_SET_TARGET_PERSISTENCE structure and passes a pointer to this structure in setPacket. Note that the first member of + /// the DISPLAYCONFIG_SET_TARGET_PERSISTENCE structure is the DISPLAYCONFIG_DEVICE_INFO_HEADER. + /// + /// + /// The function returns one of the following return codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_SUCCESS + /// The function succeeded. + /// + /// + /// ERROR_INVALID_PARAMETER + /// The combination of parameters and flags specified are invalid. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The system is not running a graphics driver that was written according to the Windows Display Driver Model (WDDM). The function + /// is only supported on a system with a WDDM driver running. + /// + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// The caller does not have access to the console session. This error occurs if the calling process does not have access to the + /// current desktop or is running on a remote session. + /// + /// + /// + /// ERROR_INSUFFICIENT_BUFFER + /// The size of the packet that the caller passes is not big enough. + /// + /// + /// ERROR_GEN_FAILURE + /// An unspecified error occurred. + /// + /// + /// + /// + /// + /// DisplayConfigSetDeviceInfo can currently only be used to start and stop boot persisted force projection on an analog + /// target. For more information about boot persistence, see Forced Versus Connected Targets. + /// + /// + /// DisplayConfigSetDeviceInfo can only be used to set DISPLAYCONFIG_DEVICE_INFO_SET_XXX type of information. + /// DisplayConfigSetDeviceInfo fails if the type member of DISPLAYCONFIG_DEVICE_INFO_HEADER is set to one of the + /// DISPLAYCONFIG_DEVICE_INFO_GET_XXX values. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-displayconfigsetdeviceinfo LONG + // DisplayConfigSetDeviceInfo( DISPLAYCONFIG_DEVICE_INFO_HEADER *setPacket ); + [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("winuser.h", MSDNShortId = "4050b1f0-a588-427c-a0df-eefdc488fc20")] + public static extern Win32Error DisplayConfigSetDeviceInfo(IntPtr setPacket); + + /// The DisplayConfigSetDeviceInfo function sets the properties of a target. + /// The type of the value to set. + /// Contains information to set for the device. + /// Supplied type does not match valid set value. + public static void DisplayConfigSetDeviceInfo(T value) where T : struct + { + if (!CorrespondingTypeAttribute.CanSet(typeof(DISPLAYCONFIG_DEVICE_INFO_TYPE), typeof(T))) throw new ArgumentException("Supplied type does not match valid set value."); + var mem = SafeHGlobalHandle.CreateFromStructure(value); + DisplayConfigSetDeviceInfo((IntPtr)mem).ThrowIfFailed(); + } + + /// + /// The GetDisplayConfigBufferSizes function retrieves the size of the buffers that are required to call the + /// QueryDisplayConfig function. + /// + /// + /// The type of information to retrieve. The value for the Flags parameter must be one of the following values. + /// QDC_ALL_PATHS + /// The caller requests the table sizes to hold all the possible path combinations. + /// QDC_ONLY_ACTIVE_PATHS + /// The caller requests the table sizes to hold only active paths. + /// QDC_DATABASE_CURRENT + /// + /// The caller requests the table sizes to hold the active paths as defined in the persistence database for the currently connected monitors. + /// + /// + /// + /// Pointer to a variable that receives the number of elements in the path information table. The pNumPathArrayElements parameter + /// value is then used by a subsequent call to the QueryDisplayConfig function. This parameter cannot be NULL. + /// + /// + /// Pointer to a variable that receives the number of elements in the mode information table. The pNumModeInfoArrayElements parameter + /// value is then used by a subsequent call to the QueryDisplayConfig function. This parameter cannot be NULL. + /// + /// + /// The function returns one of the following return codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_SUCCESS + /// The function succeeded. + /// + /// + /// ERROR_INVALID_PARAMETER + /// The combination of parameters and flags that are specified is invalid. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The system is not running a graphics driver that was written according to the Windows Display Driver Model (WDDM). The function + /// is only supported on a system with a WDDM driver running. + /// + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// The caller does not have access to the console session. This error occurs if the calling process does not have access to the + /// current desktop or is running on a remote session. + /// + /// + /// + /// ERROR_GEN_FAILURE + /// An unspecified error occurred. + /// + /// + /// + /// + /// + /// Given the current display path configuration and the requested flags, GetDisplayConfigBufferSizes returns the size of the + /// path and mode tables that are required to store the information. GetDisplayConfigBufferSizes can return values that are + /// slightly larger than are actually required because it determines that all source and target paths are valid; whereas, the driver + /// might place some restrictions on the possible combinations. + /// + /// + /// As GetDisplayConfigBufferSizes can only determine the required array size of that moment in time, it is possible that + /// between calls to GetDisplayConfigBufferSizes and QueryDisplayConfig the system configuration has changed and the provided + /// array sizes are no longer sufficient to store the new path data. + /// + /// + /// If a caller is aware that it must enable additional sources and targets, the caller can allocate a larger mode information array + /// than is returned from GetDisplayConfigBufferSizes so that it has the space to add the additional source and target modes + /// after calling QueryDisplayConfig and before calling SetDisplayConfig. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdisplayconfigbuffersizes LONG + // GetDisplayConfigBufferSizes( UINT32 flags, UINT32 *numPathArrayElements, UINT32 *numModeInfoArrayElements ); + [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("winuser.h", MSDNShortId = "5ec7f521-28b5-4922-a3fc-aa4433de69e0")] + public static extern Win32Error GetDisplayConfigBufferSizes(QDC flags, out uint numPathArrayElements, out uint numModeInfoArrayElements); + + /// + /// The QueryDisplayConfig function retrieves information about all possible display paths for all display devices, or views, + /// in the current setting. + /// + /// + /// The type of information to retrieve. The value for the Flags parameter must be one of the following values. + /// QDC_ALL_PATHS + /// All the possible path combinations of sources to targets. + /// + /// Note In the case of any temporary modes, the QDC_ALL_PATHS setting means the mode data returned may not be the same as + /// that which is stored in the persistence database. + /// + /// QDC_ONLY_ACTIVE_PATHS + /// Currently active paths only. + /// + /// Note In the case of any temporary modes, the QDC_ONLY_ACTIVE_PATHS setting means the mode data returned may not be the + /// same as that which is stored in the persistence database. + /// + /// QDC_DATABASE_CURRENT + /// Active path as defined in the CCD database for the currently connected displays. + /// + /// + /// Pointer to a variable that contains the number of elements in pPathInfoArray. This parameter cannot be NULL. If + /// QueryDisplayConfig returns ERROR_SUCCESS, pNumPathInfoElements is updated with the number of valid entries in pPathInfoArray. + /// + /// + /// Pointer to a variable that contains an array of DISPLAYCONFIG_PATH_INFO elements. Each element in pPathInfoArray describes a + /// single path from a source to a target. The source and target mode information indexes are only valid in combination with the + /// pmodeInfoArray tables that are returned for the API at the same time. This parameter cannot be NULL. The pPathInfoArray is + /// always returned in path priority order. For more information about path priority order, see Path Priority Order. + /// + /// + /// Pointer to a variable that specifies the number in element of the mode information table. This parameter cannot be NULL. + /// If QueryDisplayConfig returns ERROR_SUCCESS, pNumModeInfoArrayElements is updated with the number of valid entries in pModeInfoArray. + /// + /// + /// Pointer to a variable that contains an array of DISPLAYCONFIG_MODE_INFO elements. This parameter cannot be NULL. + /// + /// + /// + /// Pointer to a variable that receives the identifier of the currently active topology in the CCD database. For a list of possible + /// values, see the DISPLAYCONFIG_TOPOLOGY_ID enumerated type. + /// + /// The pCurrentTopologyId parameter is only set when the Flags parameter value is QDC_DATABASE_CURRENT. + /// + /// If the Flags parameter value is set to QDC_DATABASE_CURRENT, the pCurrentTopologyId parameter must not be NULL. If the + /// Flags parameter value is not set to QDC_DATABASE_CURRENT, the pCurrentTopologyId parameter value must be NULL. + /// + /// + /// + /// The function returns one of the following return codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_SUCCESS + /// The function succeeded. + /// + /// + /// ERROR_INVALID_PARAMETER + /// The combination of parameters and flags that are specified is invalid. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The system is not running a graphics driver that was written according to the Windows Display Driver Model (WDDM). The function + /// is only supported on a system with a WDDM driver running. + /// + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// The caller does not have access to the console session. This error occurs if the calling process does not have access to the + /// current desktop or is running on a remote session. + /// + /// + /// + /// ERROR_GEN_FAILURE + /// An unspecified error occurred. + /// + /// + /// ERROR_INSUFFICIENT_BUFFER + /// The supplied path and mode buffer are too small. + /// + /// + /// + /// + /// + /// As the GetDisplayConfigBufferSizes function can only determine the required array size at a particular moment in time, it is + /// possible that between calls to GetDisplayConfigBufferSizes and QueryDisplayConfig the system configuration will + /// change and the provided array sizes will no longer be sufficient to store the new path data. In this situation, + /// QueryDisplayConfig fails with ERROR_INSUFFICIENT_BUFFER, and the caller should call GetDisplayConfigBufferSizes + /// again to get the new array sizes. The caller should then allocate the correct amount of memory. + /// + /// + /// QueryDisplayConfig returns paths in the path array that the pPathInfoArray parameter specifies and the source and target + /// modes in the mode array that the pModeInfoArray parameter specifies. QueryDisplayConfig always returns paths in path + /// priority order. If QDC_ALL_PATHS is set in the Flags parameter, QueryDisplayConfig returns all the inactive paths after + /// the active paths. + /// + /// + /// Full path, source mode, and target mode information is available for all active paths. The ModeInfoIdx members in the + /// DISPLAYCONFIG_PATH_SOURCE_INFO and DISPLAYCONFIG_PATH_TARGET_INFO structures for the source and target are set up for these + /// active paths. For inactive paths, returned source and target mode information is not available; therefore, the target information + /// in the path structure is set to default values, and the source and target mode indexes are marked as invalid. For database + /// queries, if the current connect monitors have an entry, QueryDisplayConfig returns full path, source mode, and target mode + /// information (same as for active paths). However, if the database does not have a entry, QueryDisplayConfig returns just + /// the path information with the default target details (same as for inactive paths). + /// + /// + /// For an example of how source and target mode information relates to path information, see Relationship of Mode Information to + /// Path Information. + /// + /// + /// The caller can use DisplayConfigGetDeviceInfo to obtain additional information about the source or target device, for example, + /// the monitor names and monitor preferred mode and source device name. + /// + /// + /// If a target is currently being force projected, the statusFlags member of the DISPLAYCONFIG_PATH_TARGET_INFO structure has + /// one of the DISPLAYCONFIG_TARGET_FORCED_XXX flags set. + /// + /// + /// If the QDC_DATABASE_CURRENT flag is set in the Flags parameter, QueryDisplayConfig returns the topology identifier of the + /// active database topology in the variable that the pCurrentTopologyId parameter points to. If the QDC_ALL_PATHS or + /// QDC_ONLY_ACTIVE_PATHS flag is set in the Flags parameter, the pCurrentTopologyId parameter must be set to NULL; otherwise, + /// QueryDisplayConfig returns ERROR_INVALID_PARAMETER. + /// + /// + /// If a caller calls QueryDisplayConfig with the QDC_DATABASE_CURRENT flag set in the Flags parameter, + /// QueryDisplayConfig initializes the DISPLAYCONFIG_2DREGION structure that is specified in the totalSize member of + /// the DISPLAYCONFIG_VIDEO_SIGNAL_INFO structure to zeros and does not complete DISPLAYCONFIG_2DREGION. + /// + /// + /// The DEVMODE structure that is returned by the EnumDisplaySettings Win32 function (described in the Windows SDK documentation) + /// contains information that relates to both the source and target modes. However, the CCD APIs explicitly separate the source and + /// target mode components. + /// + /// DPI Virtualization + /// + /// This API does not participate in DPI virtualization. All sizes in the DEVMODE structure are in terms of physical pixels, and are + /// not related to the calling context. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-querydisplayconfig LONG QueryDisplayConfig( UINT32 flags, + // UINT32 *numPathArrayElements, DISPLAYCONFIG_PATH_INFO *pathArray, UINT32 *numModeInfoArrayElements, DISPLAYCONFIG_MODE_INFO + // *modeInfoArray, DISPLAYCONFIG_TOPOLOGY_ID *currentTopologyId ); + [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("winuser.h", MSDNShortId = "b1792d7f-f216-4250-a6b6-a11b251a9cec")] + public static extern Win32Error QueryDisplayConfig(QDC flags, ref uint numPathArrayElements, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] DISPLAYCONFIG_PATH_INFO[] pathArray, + ref uint numModeInfoArrayElements, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] DISPLAYCONFIG_MODE_INFO[] modeInfoArray, IntPtr currentTopologyId = default); + + /// + /// The QueryDisplayConfig function retrieves information about all possible display paths for all display devices, or views, + /// in the current setting. + /// + /// + /// The type of information to retrieve. The value for the Flags parameter must be one of the following values. + /// QDC_ALL_PATHS + /// All the possible path combinations of sources to targets. + /// + /// Note In the case of any temporary modes, the QDC_ALL_PATHS setting means the mode data returned may not be the same as + /// that which is stored in the persistence database. + /// + /// QDC_ONLY_ACTIVE_PATHS + /// Currently active paths only. + /// + /// Note In the case of any temporary modes, the QDC_ONLY_ACTIVE_PATHS setting means the mode data returned may not be the + /// same as that which is stored in the persistence database. + /// + /// QDC_DATABASE_CURRENT + /// Active path as defined in the CCD database for the currently connected displays. + /// + /// + /// Pointer to a variable that contains the number of elements in pPathInfoArray. This parameter cannot be NULL. If + /// QueryDisplayConfig returns ERROR_SUCCESS, pNumPathInfoElements is updated with the number of valid entries in pPathInfoArray. + /// + /// + /// Pointer to a variable that contains an array of DISPLAYCONFIG_PATH_INFO elements. Each element in pPathInfoArray describes a + /// single path from a source to a target. The source and target mode information indexes are only valid in combination with the + /// pmodeInfoArray tables that are returned for the API at the same time. This parameter cannot be NULL. The pPathInfoArray is + /// always returned in path priority order. For more information about path priority order, see Path Priority Order. + /// + /// + /// Pointer to a variable that specifies the number in element of the mode information table. This parameter cannot be NULL. + /// If QueryDisplayConfig returns ERROR_SUCCESS, pNumModeInfoArrayElements is updated with the number of valid entries in pModeInfoArray. + /// + /// + /// Pointer to a variable that contains an array of DISPLAYCONFIG_MODE_INFO elements. This parameter cannot be NULL. + /// + /// + /// + /// Pointer to a variable that receives the identifier of the currently active topology in the CCD database. For a list of possible + /// values, see the DISPLAYCONFIG_TOPOLOGY_ID enumerated type. + /// + /// The pCurrentTopologyId parameter is only set when the Flags parameter value is QDC_DATABASE_CURRENT. + /// + /// If the Flags parameter value is set to QDC_DATABASE_CURRENT, the pCurrentTopologyId parameter must not be NULL. If the + /// Flags parameter value is not set to QDC_DATABASE_CURRENT, the pCurrentTopologyId parameter value must be NULL. + /// + /// + /// + /// The function returns one of the following return codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_SUCCESS + /// The function succeeded. + /// + /// + /// ERROR_INVALID_PARAMETER + /// The combination of parameters and flags that are specified is invalid. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The system is not running a graphics driver that was written according to the Windows Display Driver Model (WDDM). The function + /// is only supported on a system with a WDDM driver running. + /// + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// The caller does not have access to the console session. This error occurs if the calling process does not have access to the + /// current desktop or is running on a remote session. + /// + /// + /// + /// ERROR_GEN_FAILURE + /// An unspecified error occurred. + /// + /// + /// ERROR_INSUFFICIENT_BUFFER + /// The supplied path and mode buffer are too small. + /// + /// + /// + /// + /// + /// As the GetDisplayConfigBufferSizes function can only determine the required array size at a particular moment in time, it is + /// possible that between calls to GetDisplayConfigBufferSizes and QueryDisplayConfig the system configuration will + /// change and the provided array sizes will no longer be sufficient to store the new path data. In this situation, + /// QueryDisplayConfig fails with ERROR_INSUFFICIENT_BUFFER, and the caller should call GetDisplayConfigBufferSizes + /// again to get the new array sizes. The caller should then allocate the correct amount of memory. + /// + /// + /// QueryDisplayConfig returns paths in the path array that the pPathInfoArray parameter specifies and the source and target + /// modes in the mode array that the pModeInfoArray parameter specifies. QueryDisplayConfig always returns paths in path + /// priority order. If QDC_ALL_PATHS is set in the Flags parameter, QueryDisplayConfig returns all the inactive paths after + /// the active paths. + /// + /// + /// Full path, source mode, and target mode information is available for all active paths. The ModeInfoIdx members in the + /// DISPLAYCONFIG_PATH_SOURCE_INFO and DISPLAYCONFIG_PATH_TARGET_INFO structures for the source and target are set up for these + /// active paths. For inactive paths, returned source and target mode information is not available; therefore, the target information + /// in the path structure is set to default values, and the source and target mode indexes are marked as invalid. For database + /// queries, if the current connect monitors have an entry, QueryDisplayConfig returns full path, source mode, and target mode + /// information (same as for active paths). However, if the database does not have a entry, QueryDisplayConfig returns just + /// the path information with the default target details (same as for inactive paths). + /// + /// + /// For an example of how source and target mode information relates to path information, see Relationship of Mode Information to + /// Path Information. + /// + /// + /// The caller can use DisplayConfigGetDeviceInfo to obtain additional information about the source or target device, for example, + /// the monitor names and monitor preferred mode and source device name. + /// + /// + /// If a target is currently being force projected, the statusFlags member of the DISPLAYCONFIG_PATH_TARGET_INFO structure has + /// one of the DISPLAYCONFIG_TARGET_FORCED_XXX flags set. + /// + /// + /// If the QDC_DATABASE_CURRENT flag is set in the Flags parameter, QueryDisplayConfig returns the topology identifier of the + /// active database topology in the variable that the pCurrentTopologyId parameter points to. If the QDC_ALL_PATHS or + /// QDC_ONLY_ACTIVE_PATHS flag is set in the Flags parameter, the pCurrentTopologyId parameter must be set to NULL; otherwise, + /// QueryDisplayConfig returns ERROR_INVALID_PARAMETER. + /// + /// + /// If a caller calls QueryDisplayConfig with the QDC_DATABASE_CURRENT flag set in the Flags parameter, + /// QueryDisplayConfig initializes the DISPLAYCONFIG_2DREGION structure that is specified in the totalSize member of + /// the DISPLAYCONFIG_VIDEO_SIGNAL_INFO structure to zeros and does not complete DISPLAYCONFIG_2DREGION. + /// + /// + /// The DEVMODE structure that is returned by the EnumDisplaySettings Win32 function (described in the Windows SDK documentation) + /// contains information that relates to both the source and target modes. However, the CCD APIs explicitly separate the source and + /// target mode components. + /// + /// DPI Virtualization + /// + /// This API does not participate in DPI virtualization. All sizes in the DEVMODE structure are in terms of physical pixels, and are + /// not related to the calling context. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-querydisplayconfig LONG QueryDisplayConfig( UINT32 flags, + // UINT32 *numPathArrayElements, DISPLAYCONFIG_PATH_INFO *pathArray, UINT32 *numModeInfoArrayElements, DISPLAYCONFIG_MODE_INFO + // *modeInfoArray, DISPLAYCONFIG_TOPOLOGY_ID *currentTopologyId ); + [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("winuser.h", MSDNShortId = "b1792d7f-f216-4250-a6b6-a11b251a9cec")] + public static extern Win32Error QueryDisplayConfig(QDC flags, ref uint numPathArrayElements, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] DISPLAYCONFIG_PATH_INFO[] pathArray, + ref uint numModeInfoArrayElements, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] DISPLAYCONFIG_MODE_INFO[] modeInfoArray, out DISPLAYCONFIG_TOPOLOGY_ID currentTopologyId); + + /// + /// The QueryDisplayConfig function retrieves information about all possible display paths for all display devices, or views, + /// in the current setting. This method also calls GetDisplayConfigBufferSizes to determine output sizing. + /// + /// + /// The type of information to retrieve. The value for the Flags parameter must be one of the following values. + /// QDC_ALL_PATHS + /// All the possible path combinations of sources to targets. + /// + /// Note In the case of any temporary modes, the QDC_ALL_PATHS setting means the mode data returned may not be the same as + /// that which is stored in the persistence database. + /// + /// QDC_ONLY_ACTIVE_PATHS + /// Currently active paths only. + /// + /// Note In the case of any temporary modes, the QDC_ONLY_ACTIVE_PATHS setting means the mode data returned may not be the + /// same as that which is stored in the persistence database. + /// + /// QDC_DATABASE_CURRENT + /// Active path as defined in the CCD database for the currently connected displays. + /// + /// + /// The resulting array of DISPLAYCONFIG_PATH_INFO elements. Each element in pPathInfoArray describes a single path from a source to + /// a target. The source and target mode information indexes are only valid in combination with the pmodeInfoArray tables that are + /// returned for the API at the same time. This parameter cannot be NULL. The pPathInfoArray is always returned in path + /// priority order. For more information about path priority order, see Path Priority Order. + /// + /// The resulting array of DISPLAYCONFIG_MODE_INFO elements. + /// + /// + /// Pointer to a variable that receives the identifier of the currently active topology in the CCD database. For a list of possible + /// values, see the DISPLAYCONFIG_TOPOLOGY_ID enumerated type. + /// + /// The pCurrentTopologyId parameter is only set when the Flags parameter value is QDC_DATABASE_CURRENT. + /// + /// If the Flags parameter value is set to QDC_DATABASE_CURRENT, the pCurrentTopologyId parameter must not be NULL. If the + /// Flags parameter value is not set to QDC_DATABASE_CURRENT, the pCurrentTopologyId parameter value must be NULL. + /// + /// + /// + /// The function returns one of the following return codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_SUCCESS + /// The function succeeded. + /// + /// + /// ERROR_INVALID_PARAMETER + /// The combination of parameters and flags that are specified is invalid. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The system is not running a graphics driver that was written according to the Windows Display Driver Model (WDDM). The function + /// is only supported on a system with a WDDM driver running. + /// + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// The caller does not have access to the console session. This error occurs if the calling process does not have access to the + /// current desktop or is running on a remote session. + /// + /// + /// + /// ERROR_GEN_FAILURE + /// An unspecified error occurred. + /// + /// + /// ERROR_INSUFFICIENT_BUFFER + /// The supplied path and mode buffer are too small. + /// + /// + /// + /// + /// + /// QueryDisplayConfig returns paths in the path array that the pPathInfoArray parameter specifies and the source and target + /// modes in the mode array that the pModeInfoArray parameter specifies. QueryDisplayConfig always returns paths in path + /// priority order. If QDC_ALL_PATHS is set in the Flags parameter, QueryDisplayConfig returns all the inactive paths after + /// the active paths. + /// + /// + /// Full path, source mode, and target mode information is available for all active paths. The ModeInfoIdx members in the + /// DISPLAYCONFIG_PATH_SOURCE_INFO and DISPLAYCONFIG_PATH_TARGET_INFO structures for the source and target are set up for these + /// active paths. For inactive paths, returned source and target mode information is not available; therefore, the target information + /// in the path structure is set to default values, and the source and target mode indexes are marked as invalid. For database + /// queries, if the current connect monitors have an entry, QueryDisplayConfig returns full path, source mode, and target mode + /// information (same as for active paths). However, if the database does not have a entry, QueryDisplayConfig returns just + /// the path information with the default target details (same as for inactive paths). + /// + /// + /// For an example of how source and target mode information relates to path information, see Relationship of Mode Information to + /// Path Information. + /// + /// + /// The caller can use DisplayConfigGetDeviceInfo to obtain additional information about the source or target device, for example, + /// the monitor names and monitor preferred mode and source device name. + /// + /// + /// If a target is currently being force projected, the statusFlags member of the DISPLAYCONFIG_PATH_TARGET_INFO structure has + /// one of the DISPLAYCONFIG_TARGET_FORCED_XXX flags set. + /// + /// + /// If the QDC_DATABASE_CURRENT flag is set in the Flags parameter, QueryDisplayConfig returns the topology identifier of the + /// active database topology in the variable that the pCurrentTopologyId parameter points to. If the QDC_ALL_PATHS or + /// QDC_ONLY_ACTIVE_PATHS flag is set in the Flags parameter, the pCurrentTopologyId parameter must be set to NULL; otherwise, + /// QueryDisplayConfig returns ERROR_INVALID_PARAMETER. + /// + /// + /// If a caller calls QueryDisplayConfig with the QDC_DATABASE_CURRENT flag set in the Flags parameter, + /// QueryDisplayConfig initializes the DISPLAYCONFIG_2DREGION structure that is specified in the totalSize member of + /// the DISPLAYCONFIG_VIDEO_SIGNAL_INFO structure to zeros and does not complete DISPLAYCONFIG_2DREGION. + /// + /// + /// The DEVMODE structure that is returned by the EnumDisplaySettings Win32 function (described in the Windows SDK documentation) + /// contains information that relates to both the source and target modes. However, the CCD APIs explicitly separate the source and + /// target mode components. + /// + /// DPI Virtualization + /// + /// This API does not participate in DPI virtualization. All sizes in the DEVMODE structure are in terms of physical pixels, and are + /// not related to the calling context. + /// + /// + [PInvokeData("winuser.h", MSDNShortId = "b1792d7f-f216-4250-a6b6-a11b251a9cec")] + public static Win32Error QueryDisplayConfig(QDC flags, out DISPLAYCONFIG_PATH_INFO[] pathArray, out DISPLAYCONFIG_MODE_INFO[] modeInfoArray, out DISPLAYCONFIG_TOPOLOGY_ID currentTopologyId) + { + Win32Error err; + do + { + err = GetDisplayConfigBufferSizes(flags, out var cPath, out var cMode); + pathArray = new DISPLAYCONFIG_PATH_INFO[err.Failed ? 0 : cPath]; + modeInfoArray = new DISPLAYCONFIG_MODE_INFO[err.Failed ? 0 : cMode]; + currentTopologyId = 0; + if (err.Failed) return err; + if (flags.IsFlagSet(QDC.QDC_DATABASE_CURRENT)) + err = QueryDisplayConfig(flags, ref cPath, pathArray, ref cMode, modeInfoArray, out currentTopologyId); + else + err = QueryDisplayConfig(flags, ref cPath, pathArray, ref cMode, modeInfoArray); + if (err.Succeeded || err != Win32Error.ERROR_INSUFFICIENT_BUFFER) return err; + } while (err == Win32Error.ERROR_INSUFFICIENT_BUFFER); + return err; + } + + /// + /// The SetDisplayConfig function modifies the display topology, source, and target modes by exclusively enabling the + /// specified paths in the current session. + /// + /// Number of elements in pathArray. + /// + /// Array of all display paths that are to be set. Only the paths within this array that have the DISPLAYCONFIG_PATH_ACTIVE flag set + /// in the flags member of DISPLAYCONFIG_PATH_INFO are set. This parameter can be NULL. The order in which active paths + /// appear in this array determines the path priority. For more information about path priority order, see Path Priority Order. + /// + /// Number of elements in modeInfoArray. + /// + /// Array of display source and target mode information (DISPLAYCONFIG_MODE_INFO) that is referenced by the modeInfoIdx member + /// of DISPLAYCONFIG_PATH_SOURCE_INFO and DISPLAYCONFIG_PATH_TARGET_INFO element of path information from pathArray. This parameter + /// can be NULL. + /// + /// + /// + /// A bitwise OR of flag values that indicates the behavior of this function. This parameter can be one the following values, or a + /// combination of the following values; 0 is not valid. + /// + /// SDC_APPLY + /// The resulting topology, source, and target mode is set. + /// SDC_NO_OPTIMIZATION + /// + /// A modifier to the SDC_APPLY flag. This causes the change mode to be forced all the way down to the driver for each active display. + /// + /// SDC_USE_SUPPLIED_DISPLAY_CONFIG + /// + /// The topology, source, and target mode information that are supplied in the pathArray and the modeInfoArray parameters are used, + /// rather than looking up the configuration in the database. + /// + /// SDC_SAVE_TO_DATABASE + /// The resulting topology, source, and target mode are saved to the database. + /// SDC_VALIDATE + /// The system tests for the requested topology, source, and target mode information to determine whether it can be set. + /// SDC_ALLOW_CHANGES + /// + /// If required, the function can modify the specified source and target mode information in order to create a functional display + /// path set. + /// + /// SDC_TOPOLOGY_CLONE + /// The caller requests the last clone configuration from the persistence database. + /// SDC_TOPOLOGY_EXTEND + /// The caller requests the last extended configuration from the persistence database. + /// SDC_TOPOLOGY_INTERNAL + /// The caller requests the last internal configuration from the persistence database. + /// SDC_TOPOLOGY_EXTERNAL + /// The caller requests the last external configuration from the persistence database. + /// SDC_TOPOLOGY_SUPPLIED + /// + /// The caller provides the path data so the function only queries the persistence database to find and use the source and target mode. + /// + /// SDC_USE_DATABASE_CURRENT + /// + /// The caller requests a combination of all four SDC_TOPOLOGY_XXX configurations. This value informs the API to set the last known + /// display configuration for the current connected monitors. + /// + /// SDC_PATH_PERSIST_IF_REQUIRED + /// + /// When the function processes a SDC_TOPOLOGY_XXX request, it can force path persistence on a target to satisfy the request if + /// necessary. For information about the other flags that this flag can be combined with, see the following list. + /// + /// SDC_FORCE_MODE_ENUMERATION + /// + /// The caller requests that the driver is given an opportunity to update the GDI mode list while SetDisplayConfig sets the + /// new display configuration. This flag value is only valid when the SDC_USE_SUPPLIED_DISPLAY_CONFIG and SDC_APPLY flag values are + /// also specified. + /// + /// SDC_ALLOW_PATH_ORDER_CHANGES + /// + /// A modifier to the SDC_TOPOLOGY_SUPPLIED flag that indicates that SetDisplayConfig should ignore the path order of the + /// supplied topology when searching the database. When this flag is set, the topology set is the most recent topology that contains + /// all the paths regardless of the path order. + /// + /// The following list contains valid combinations of values for the Flags parameter: + /// + /// + /// Either SDC_APPLY or SDC_VALIDATE must be set, but not both. + /// + /// + /// + /// Either SDC_USE_SUPPLIED_DISPLAY_CONFIG or any combinations of SDC_TOPOLOGY_XXX must be set. SDC_USE_SUPPLIED_DISPLAY_CONFIG + /// cannot be set with any SDC_TOPOLOGY_XXX flag. + /// + /// + /// + /// SDC_NO_OPTIMIZATION can only be set with SDC_APPLY. + /// + /// + /// SDC_ALLOW_CHANGES is allowed with any other valid combination. + /// + /// + /// SDC_SAVE_TO_DATABASE can only be set with SDC_USE_SUPPLIED_DISPLAY_CONFIG. + /// + /// + /// SDC_PATH_PERSIST_IF_REQUIRED cannot be used with SDC_USE_SUPPLIED_DISPLAY_CONFIG or SDC_TOPOLOGY_SUPPLIED. + /// + /// + /// SDC_FORCE_MODE_ENUMERATION is only valid when SDC_APPLY and SDC_USE_SUPPLIED_DISPLAY_CONFIG are specified. + /// + /// + /// SDC_ALLOW_PATH_ORDER_CHANGES is allowed only when SDC_TOPOLOGY_SUPPLIED is specified. + /// + /// + /// + /// SDC_TOPOLOGY_SUPPLIED cannot be used with any other SDC_TOPOLOGY_XXX flag. Because of a validation issue, if a caller violates + /// this rule, SetDisplayConfig does not fail. However, SetDisplayConfig ignores the SDC_TOPOLOGY_SUPPLIED flag. + /// + /// + /// + /// + /// SDC_TOPOLOGY_XXX flags can be used in combinations. For example, if SDC_TOPOLOGY_CLONE and SDC_TOPOLOGY_EXTEND are set, the API + /// uses the most recent clone or extend topology, which every topology was set with most recently for the current connected monitors. + /// + /// + /// + /// The function returns one of the following return codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_SUCCESS + /// The function succeeded. + /// + /// + /// ERROR_INVALID_PARAMETER + /// The combination of parameters and flags specified is invalid. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The system is not running a graphics driver that was written according to the Windows Display Driver Model (WDDM). The function + /// is only supported on a system with a WDDM driver running. + /// + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// The caller does not have access to the console session. This error occurs if the calling process does not have access to the + /// current desktop or is running on a remote session. + /// + /// + /// + /// ERROR_GEN_FAILURE + /// An unspecified error occurred. + /// + /// + /// ERROR_BAD_CONFIGURATION + /// The function could not find a workable solution for the source and target modes that the caller did not specify. + /// + /// + /// + /// + /// + /// The SetDisplayConfig function takes the active display paths with any specified source and target mode information and + /// uses best mode logic to generate any missing source and target mode information. This function then sets the complete display path. + /// + /// + /// The ModeInfoIdx members in the DISPLAYCONFIG_PATH_SOURCE_INFO and DISPLAYCONFIG_PATH_TARGET_INFO structures are used to + /// indicate whether source and target mode are supplied for a given active path. If the index value is + /// DISPLAYCONFIG_PATH_MODE_IDX_INVALID for either, this indicates the mode information is not being specified. It is valid for the + /// path plus source mode or the path plus source and target mode information to be specified for a given path. However, it is not + /// valid for the path plus target mode to be specified without the source mode. + /// + /// + /// The source and target modes for each source and target identifiers can only appear in the modeInfoArray array once. For example, + /// a source mode for source identifier S1 can only appear in the table once; if multiple paths reference the same source, they have + /// to use the same ModeInfoIdx. + /// + /// + /// The expectation is that most callers use QueryDisplayConfig to get the current configuration along with other valid possibilities + /// and then use SetDisplayConfig to test and set the configuration. + /// + /// The order in which the active paths appear in the PathArray array determines the path priority. + /// + /// By default, SetDisplayConfig never changes any supplied path, source mode, or target mode information. If best mode logic + /// cannot find a solution without changing the specified display path information, SetDisplayConfig fails with + /// ERROR_BAD_CONFIGURATION. In this case, the caller should specify the SDC_ALLOW_CHANGES flag to allow the function to tweak some + /// of the specified source and mode details to allow the display path change to be successful. + /// + /// + /// If the specified or calculated source and target modes have the same dimensions, SetDisplayConfig automatically sets the + /// path scaling to DISPLAYCONFIG_PPR_IDENTITY before setting the display path and saving it in the database. For information about + /// how SetDisplayConfig handles scaling, see Scaling the Desktop Image. + /// + /// + /// When the caller specifies the SDC_USE_SUPPLIED_DISPLAY_CONFIG flag to set a clone path and if any source mode indexes are invalid + /// in the path array, SetDisplayConfig determines that all of the source mode indexes from that source are invalid. + /// SetDisplayConfig uses the best mode logic to determine the source mode information. + /// + /// + /// Except for the SDC_TOPOLOGY_SUPPLIED flag (for more information about SDC_TOPOLOGY_SUPPLIED, see the following paragraph), the + /// SDC_TOPOLOGY_XXX flags set last display path settings, including the source and target mode information for that topology type. + /// For information about valid SDC_TOPOLOGY_XXX flag combinations, see the Flags parameter description. The pathArray and + /// modeInfoArray parameters must be NULL, and their associated sizes must be zero. For example, if SDC_TOPOLOGY_CLONE and + /// SDC_TOPOLOGY_EXTEND are set, this function uses the most recent clone or extend display path configuration. If a single topology + /// type is requested, the last configuration of that type is used. If that topology had never been set before, + /// SetDisplayConfig uses the best topology logic to find the best topology, and then best mode logic to find the best source + /// and target mode to use. If a combination of the topology flags had been set and none of them had database entries, the following + /// priority is used. For laptops: clone, extend, internal, and then external; for desktops the priority is extend and then clone. + /// + /// + /// The caller can specify the SDC_TOPOLOGY_SUPPLIED flag to indicate that it sets just the path information (topology) and requests + /// that SetDisplayConfig obtains and then uses the source and target mode information from the persistence database. If the + /// active paths that the caller supplies do not have an entry in the persistence database, SetDisplayConfig fails. In this + /// case, if the caller calls SetDisplayConfig again with the same path data but with the SDC_USE_SUPPLIED_DISPLAY_CONFIG flag + /// set, SetDisplayConfig uses best mode logic to create the source and target mode information. When the caller specifies + /// SDC_TOPOLOGY_SUPPLIED, the caller must set the numModeInfoArrayElements parameter to zero and the modeInfoArray parameter to + /// NULL; however, the caller must set the pathArray and numPathArrayElements parameters for the path information that the + /// caller requires. The caller must mark all the source and target mode indexes as invalid (DISPLAYCONFIG_PATH_MODE_IDX_INVALID) in + /// this path data. + /// + /// + /// The following table provides some common scenarios where SetDisplayConfig is called along with the flag combinations that + /// the caller passes to the Flags parameter to achieve the scenarios. + /// + /// + /// + /// Scenario + /// Flag combination + /// + /// + /// Test whether a specified display configuration is supported on the computer + /// SDC_VALIDATE | SDC_USE_SUPPLIED_DISPLAY_CONFIG + /// + /// + /// Set a specified display configuration and save to the database + /// SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE + /// + /// + /// Set a temporary display configuration (that is, the display configuration will not be saved) + /// SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG + /// + /// + /// Test whether clone is supported on the computer + /// SDC_VALIDATE | SDC_TOPOLOGY_CLONE + /// + /// + /// Set clone topology + /// SDC_APPLY | SDC_TOPOLOGY_CLONE + /// + /// + /// Set clone topology and allow path persistence to be enabled if required to satisfy the request + /// SDC_APPLY | SDC_TOPOLOGY_CLONE | SDC_PATH_PERSIST_IF_REQUIRED + /// + /// + /// Return from a temporary mode to the last saved display configuration + /// SDC_APPLY| SDC_USE_DATABASE_CURRENT + /// + /// + /// + /// Given only the path information, set the display configuration with the source and target information from the database for the + /// paths and ignore the path order + /// + /// SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES + /// + /// + /// DPI Virtualization + /// + /// This API does not participate in DPI virtualization. All sizes in the DEVMODE structure are in terms of physical pixels, and are + /// not related to the calling context. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setdisplayconfig LONG SetDisplayConfig( UINT32 + // numPathArrayElements, DISPLAYCONFIG_PATH_INFO *pathArray, UINT32 numModeInfoArrayElements, DISPLAYCONFIG_MODE_INFO *modeInfoArray, + // UINT32 flags ); + [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("winuser.h", MSDNShortId = "9f649fa0-ffb2-44c6-9a66-049f888e3b04")] + public static extern Win32Error SetDisplayConfig(uint numPathArrayElements, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Optional] DISPLAYCONFIG_PATH_INFO[] pathArray, + uint numModeInfoArrayElements, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2), Optional] DISPLAYCONFIG_MODE_INFO[] modeInfoArray, SDC flags); + } +} \ No newline at end of file diff --git a/UnitTests/PInvoke/User32/User32Tests.cs b/UnitTests/PInvoke/User32/User32Tests.cs index ff7d0188..f5267020 100644 --- a/UnitTests/PInvoke/User32/User32Tests.cs +++ b/UnitTests/PInvoke/User32/User32Tests.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using System; +using System.Linq; using System.Runtime.InteropServices; using Vanara.InteropServices; using static Vanara.PInvoke.Gdi32; @@ -55,6 +56,28 @@ namespace Vanara.PInvoke.Tests } } + [Test] + public void DisplayConfigTest() + { + Assert.That(QueryDisplayConfig(QDC.QDC_ONLY_ACTIVE_PATHS, out var paths, out var modes, out var topId).Succeeded, Is.True); + foreach (var mode in modes.Where(m => m.infoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)) + { + Assert.That(() => DisplayConfigGetDeviceInfo(mode.adapterId, mode.id, DISPLAYCONFIG_DEVICE_INFO_TYPE.DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME), Throws.Exception); + Assert.That(() => DisplayConfigGetDeviceInfo(mode.adapterId, mode.id), Throws.Exception); + TestContext.WriteLine(DisplayConfigGetDeviceInfo(mode.adapterId, mode.id).monitorFriendlyDeviceName); + TestContext.WriteLine(DisplayConfigGetDeviceInfo(mode.adapterId, mode.id).adapterDevicePath); + TestContext.WriteLine(DisplayConfigGetDeviceInfo(mode.adapterId, mode.id).baseOutputTechnology); + TestContext.WriteLine(DisplayConfigGetDeviceInfo(mode.adapterId, mode.id).value); + TestContext.WriteLine(DisplayConfigGetDeviceInfo(mode.adapterId, mode.id).colorEncoding); + TestContext.WriteLine(DisplayConfigGetDeviceInfo(mode.adapterId, mode.id).SDRWhiteLevel); + TestContext.WriteLine(DisplayConfigGetDeviceInfo(mode.adapterId, mode.id).targetMode); + } + foreach (var path in paths.Where(p => p.targetInfo.targetAvailable)) + { + TestContext.WriteLine(DisplayConfigGetDeviceInfo(path.sourceInfo.adapterId, path.sourceInfo.id).viewGdiDeviceName); + } + } + [Test()] public void GetActiveWindowTest() {