mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Gamma Init
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains possible values for the result of mode change request
|
||||
/// </summary>
|
||||
public enum ChangeDisplaySettingsExResults
|
||||
{
|
||||
/// <summary>
|
||||
/// Completed successfully
|
||||
/// </summary>
|
||||
Successful = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Changes needs restart
|
||||
/// </summary>
|
||||
Restart = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Failed to change and save setings
|
||||
/// </summary>
|
||||
Failed = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Invalid data provide
|
||||
/// </summary>
|
||||
BadMode = -2,
|
||||
|
||||
/// <summary>
|
||||
/// Changes not updated
|
||||
/// </summary>
|
||||
NotUpdated = -3,
|
||||
|
||||
/// <summary>
|
||||
/// Invalid flags provided
|
||||
/// </summary>
|
||||
BadFlags = -4,
|
||||
|
||||
/// <summary>
|
||||
/// Bad parameters provided
|
||||
/// </summary>
|
||||
BadParam = -5,
|
||||
|
||||
/// <summary>
|
||||
/// Bad Dual View mode used with mode
|
||||
/// </summary>
|
||||
BadDualView = -6
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
[Flags]
|
||||
internal enum ChangeDisplaySettingsFlags : uint
|
||||
{
|
||||
UpdateRegistry = 0x00000001,
|
||||
|
||||
Global = 0x00000008,
|
||||
|
||||
SetPrimary = 0x00000010,
|
||||
|
||||
Reset = 0x40000000,
|
||||
|
||||
NoReset = 0x10000000
|
||||
}
|
||||
}
|
||||
56
app/WindowsDisplayAPI/Native/DeviceContext/DCHandle.cs
Normal file
56
app/WindowsDisplayAPI/Native/DeviceContext/DCHandle.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
internal class DCHandle : SafeHandle
|
||||
{
|
||||
private readonly bool _created;
|
||||
|
||||
private DCHandle(IntPtr handle, bool created) : base(handle, true)
|
||||
{
|
||||
_created = created;
|
||||
}
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get => handle == IntPtr.Zero;
|
||||
}
|
||||
|
||||
public static DCHandle CreateFromDevice(string screenName, string devicePath)
|
||||
{
|
||||
return new DCHandle(
|
||||
DeviceContextApi.CreateDC(screenName, devicePath, null, IntPtr.Zero),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public static DCHandle CreateFromScreen(string screenName)
|
||||
{
|
||||
return CreateFromDevice(screenName, screenName);
|
||||
}
|
||||
|
||||
public static DCHandle CreateFromWindow(IntPtr windowHandle)
|
||||
{
|
||||
return new DCHandle(
|
||||
DeviceContextApi.GetDC(windowHandle),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public static DCHandle CreateGlobal()
|
||||
{
|
||||
return new DCHandle(
|
||||
DeviceContextApi.CreateDC("DISPLAY", null, null, IntPtr.Zero),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return _created
|
||||
? DeviceContextApi.DeleteDC(this.handle)
|
||||
: DeviceContextApi.ReleaseDC(IntPtr.Zero, this.handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
internal enum DeviceCapability
|
||||
{
|
||||
DriverVersion = 0,
|
||||
Technology = 2,
|
||||
HorizontalSizeInMM = 4,
|
||||
VerticalSizeInMM = 6,
|
||||
HorizontalResolution = 8,
|
||||
VerticalResolution = 10,
|
||||
BitsPerPixel = 12,
|
||||
Planes = 14,
|
||||
NumberOfBrushes = 16,
|
||||
NumberOfPens = 18,
|
||||
NumberOfMarkers = 20,
|
||||
NumberOfFonts = 22,
|
||||
NumberOfColors = 24,
|
||||
DeviceDescriptorSize = 26,
|
||||
CurveCapabilities = 28,
|
||||
LineCapabilities = 30,
|
||||
PolygonalCapabilities = 32,
|
||||
TextCapabilities = 34,
|
||||
ClipCapabilities = 36,
|
||||
RasterCapabilities = 38,
|
||||
HorizontalAspect = 40,
|
||||
VerticalAspect = 42,
|
||||
HypotenuseAspect = 44,
|
||||
//ShadeBlendingCapabilities = 45,
|
||||
HorizontalLogicalPixels = 88,
|
||||
VerticalLogicalPixels = 90,
|
||||
PaletteSize = 104,
|
||||
ReservedPaletteSize = 106,
|
||||
ColorResolution = 108,
|
||||
|
||||
// Printer Only
|
||||
PhysicalWidth = 110,
|
||||
PhysicalHeight = 111,
|
||||
PhysicalHorizontalMargin = 112,
|
||||
PhysicalVerticalMargin = 113,
|
||||
HorizontalScalingFactor = 114,
|
||||
VerticalScalingFactor = 115,
|
||||
|
||||
// Display Only
|
||||
VerticalRefreshRateInHz = 116,
|
||||
DesktopVerticalResolution = 117,
|
||||
DesktopHorizontalResolution = 118,
|
||||
PreferredBLTAlignment = 119,
|
||||
ShadeBlendingCapabilities = 120,
|
||||
ColorManagementCapabilities = 121,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
[Flags]
|
||||
internal enum DeviceModeFields : uint
|
||||
{
|
||||
None = 0,
|
||||
|
||||
Position = 0x20,
|
||||
|
||||
DisplayOrientation = 0x80,
|
||||
|
||||
Color = 0x800,
|
||||
|
||||
Duplex = 0x1000,
|
||||
|
||||
YResolution = 0x2000,
|
||||
|
||||
TtOption = 0x4000,
|
||||
|
||||
Collate = 0x8000,
|
||||
|
||||
FormName = 0x10000,
|
||||
|
||||
LogPixels = 0x20000,
|
||||
|
||||
BitsPerPixel = 0x40000,
|
||||
|
||||
PelsWidth = 0x80000,
|
||||
|
||||
PelsHeight = 0x100000,
|
||||
|
||||
DisplayFlags = 0x200000,
|
||||
|
||||
DisplayFrequency = 0x400000,
|
||||
|
||||
DisplayFixedOutput = 0x20000000,
|
||||
|
||||
AllDisplay = Position |
|
||||
DisplayOrientation |
|
||||
YResolution |
|
||||
BitsPerPixel |
|
||||
PelsWidth |
|
||||
PelsHeight |
|
||||
DisplayFlags |
|
||||
DisplayFrequency |
|
||||
DisplayFixedOutput,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
[Flags]
|
||||
internal enum DisplayDeviceStateFlags : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// The device is part of the desktop.
|
||||
/// </summary>
|
||||
AttachedToDesktop = 0x1,
|
||||
MultiDriver = 0x2,
|
||||
|
||||
/// <summary>
|
||||
/// The device is part of the desktop.
|
||||
/// </summary>
|
||||
PrimaryDevice = 0x4,
|
||||
|
||||
/// <summary>
|
||||
/// Represents a pseudo device used to mirror application drawing for remoting or other purposes.
|
||||
/// </summary>
|
||||
MirroringDriver = 0x8,
|
||||
|
||||
/// <summary>
|
||||
/// The device is VGA compatible.
|
||||
/// </summary>
|
||||
VGACompatible = 0x10,
|
||||
|
||||
/// <summary>
|
||||
/// The device is removable; it cannot be the primary display.
|
||||
/// </summary>
|
||||
Removable = 0x20,
|
||||
|
||||
/// <summary>
|
||||
/// The device has more display modes than its output devices support.
|
||||
/// </summary>
|
||||
ModesPruned = 0x8000000,
|
||||
Remote = 0x4000000,
|
||||
Disconnect = 0x2000000
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains possible values for the display fixed output
|
||||
/// </summary>
|
||||
public enum DisplayFixedOutput : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Default behavior
|
||||
/// </summary>
|
||||
Default = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Stretches the output to fit to the display
|
||||
/// </summary>
|
||||
Stretch = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Centers the output in the middle of the display
|
||||
/// </summary>
|
||||
Center = 2
|
||||
}
|
||||
}
|
||||
12
app/WindowsDisplayAPI/Native/DeviceContext/DisplayFlags.cs
Normal file
12
app/WindowsDisplayAPI/Native/DeviceContext/DisplayFlags.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
[Flags]
|
||||
internal enum DisplayFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
Grayscale = 1,
|
||||
Interlaced = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains possible values for the display orientation
|
||||
/// </summary>
|
||||
public enum DisplayOrientation : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// No rotation
|
||||
/// </summary>
|
||||
Identity = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 90 degree rotation
|
||||
/// </summary>
|
||||
Rotate90Degree = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 180 degree rotation
|
||||
/// </summary>
|
||||
Rotate180Degree = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 270 degree rotation
|
||||
/// </summary>
|
||||
Rotate270Degree = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
internal enum DisplaySettingsMode
|
||||
{
|
||||
CurrentSettings = -1,
|
||||
|
||||
RegistrySettings = -2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
internal enum DisplayTechnology : int
|
||||
{
|
||||
Plotter = 0,
|
||||
RasterDisplay = 1,
|
||||
RasterPrinter = 2,
|
||||
RasterCamera = 3,
|
||||
CharacterStream = 4,
|
||||
MetaFile = 5,
|
||||
DisplayFile = 6,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
internal enum MonitorFromFlag : uint
|
||||
{
|
||||
DefaultToNull = 0,
|
||||
DefaultToPrimary = 1,
|
||||
DefaultToNearest = 2,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
[Flags]
|
||||
internal enum MonitorInfoFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
Primary = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd183565(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
|
||||
internal struct DeviceMode
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] [FieldOffset(0)]
|
||||
public readonly string DeviceName;
|
||||
|
||||
[MarshalAs(UnmanagedType.U2)] [FieldOffset(32)]
|
||||
public readonly ushort SpecificationVersion;
|
||||
|
||||
[MarshalAs(UnmanagedType.U2)] [FieldOffset(34)]
|
||||
public readonly ushort DriverVersion;
|
||||
|
||||
[MarshalAs(UnmanagedType.U2)] [FieldOffset(36)]
|
||||
public readonly ushort Size;
|
||||
|
||||
[MarshalAs(UnmanagedType.U2)] [FieldOffset(38)]
|
||||
public readonly ushort DriverExtra;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(40)]
|
||||
public readonly DeviceModeFields Fields;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(44)]
|
||||
public readonly PointL Position;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(52)]
|
||||
public readonly DisplayOrientation DisplayOrientation;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(56)]
|
||||
public readonly DisplayFixedOutput DisplayFixedOutput;
|
||||
|
||||
[MarshalAs(UnmanagedType.I2)] [FieldOffset(60)]
|
||||
public readonly short Color;
|
||||
|
||||
[MarshalAs(UnmanagedType.I2)] [FieldOffset(62)]
|
||||
public readonly short Duplex;
|
||||
|
||||
[MarshalAs(UnmanagedType.I2)] [FieldOffset(64)]
|
||||
public readonly short YResolution;
|
||||
|
||||
[MarshalAs(UnmanagedType.I2)] [FieldOffset(66)]
|
||||
public readonly short TrueTypeOption;
|
||||
|
||||
[MarshalAs(UnmanagedType.I2)] [FieldOffset(68)]
|
||||
public readonly short Collate;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] [FieldOffset(72)]
|
||||
private readonly string FormName;
|
||||
|
||||
[MarshalAs(UnmanagedType.U2)] [FieldOffset(102)]
|
||||
public readonly ushort LogicalInchPixels;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(104)]
|
||||
public readonly uint BitsPerPixel;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(108)]
|
||||
public readonly uint PixelsWidth;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(112)]
|
||||
public readonly uint PixelsHeight;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(116)]
|
||||
public readonly DisplayFlags DisplayFlags;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(120)]
|
||||
public readonly uint DisplayFrequency;
|
||||
|
||||
public DeviceMode(DeviceModeFields fields) : this()
|
||||
{
|
||||
SpecificationVersion = 0x0320;
|
||||
Size = (ushort) Marshal.SizeOf(GetType());
|
||||
Fields = fields;
|
||||
}
|
||||
|
||||
public DeviceMode(string deviceName, DeviceModeFields fields) : this(fields)
|
||||
{
|
||||
DeviceName = deviceName;
|
||||
}
|
||||
|
||||
public DeviceMode(
|
||||
string deviceName,
|
||||
PointL position,
|
||||
DisplayOrientation orientation,
|
||||
DisplayFixedOutput fixedOutput,
|
||||
uint bpp,
|
||||
uint width,
|
||||
uint height,
|
||||
DisplayFlags displayFlags,
|
||||
uint displayFrequency) : this(
|
||||
deviceName,
|
||||
DeviceModeFields.Position |
|
||||
DeviceModeFields.DisplayOrientation |
|
||||
DeviceModeFields.DisplayFixedOutput |
|
||||
DeviceModeFields.BitsPerPixel |
|
||||
DeviceModeFields.PelsWidth |
|
||||
DeviceModeFields.PelsHeight |
|
||||
DeviceModeFields.DisplayFlags |
|
||||
DeviceModeFields.DisplayFrequency
|
||||
)
|
||||
{
|
||||
Position = position;
|
||||
DisplayOrientation = orientation;
|
||||
DisplayFixedOutput = fixedOutput;
|
||||
BitsPerPixel = bpp;
|
||||
PixelsWidth = width;
|
||||
PixelsHeight = height;
|
||||
DisplayFlags = displayFlags;
|
||||
DisplayFrequency = displayFrequency;
|
||||
}
|
||||
|
||||
public DeviceMode(string deviceName, PointL position, uint bpp, uint width, uint height, uint displayFrequency)
|
||||
: this(
|
||||
deviceName,
|
||||
DeviceModeFields.Position |
|
||||
DeviceModeFields.BitsPerPixel |
|
||||
DeviceModeFields.PelsWidth |
|
||||
DeviceModeFields.PelsHeight |
|
||||
DeviceModeFields.DisplayFrequency
|
||||
)
|
||||
{
|
||||
Position = position;
|
||||
BitsPerPixel = bpp;
|
||||
PixelsWidth = width;
|
||||
PixelsHeight = height;
|
||||
DisplayFrequency = displayFrequency;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext.Structures
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayDevice
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] internal uint Size;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||
public readonly string DeviceName;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public readonly string DeviceString;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayDeviceStateFlags StateFlags;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public readonly string DeviceId;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public readonly string DeviceKey;
|
||||
|
||||
public static DisplayDevice Initialize()
|
||||
{
|
||||
return new DisplayDevice
|
||||
{
|
||||
Size = (uint) Marshal.SizeOf(typeof(DisplayDevice))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext.Structures
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GammaRamp
|
||||
{
|
||||
public const int DataPoints = 256;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DataPoints)]
|
||||
public readonly ushort[] Red;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DataPoints)]
|
||||
public readonly ushort[] Green;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DataPoints)]
|
||||
public readonly ushort[] Blue;
|
||||
|
||||
public GammaRamp(ushort[] red, ushort[] green, ushort[] blue)
|
||||
{
|
||||
if (red == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(red));
|
||||
}
|
||||
|
||||
if (green == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(green));
|
||||
}
|
||||
|
||||
if (blue == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(blue));
|
||||
}
|
||||
|
||||
if (red.Length != DataPoints)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(red));
|
||||
}
|
||||
|
||||
if (green.Length != DataPoints)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(green));
|
||||
}
|
||||
|
||||
if (blue.Length != DataPoints)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(blue));
|
||||
}
|
||||
|
||||
Red = red;
|
||||
Green = green;
|
||||
Blue = blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext.Structures
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct MonitorInfo
|
||||
{
|
||||
internal uint Size;
|
||||
public readonly RectangleL Bounds;
|
||||
public readonly RectangleL WorkingArea;
|
||||
public readonly MonitorInfoFlags Flags;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||
public readonly string DisplayName;
|
||||
|
||||
public static MonitorInfo Initialize()
|
||||
{
|
||||
return new MonitorInfo
|
||||
{
|
||||
Size = (uint)Marshal.SizeOf(typeof(MonitorInfo))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
106
app/WindowsDisplayAPI/Native/DeviceContextApi.cs
Normal file
106
app/WindowsDisplayAPI/Native/DeviceContextApi.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.DeviceContext;
|
||||
using WindowsDisplayAPI.Native.DeviceContext.Structures;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native
|
||||
{
|
||||
internal class DeviceContextApi
|
||||
{
|
||||
[DllImport("user32", CharSet = CharSet.Ansi)]
|
||||
public static extern ChangeDisplaySettingsExResults ChangeDisplaySettingsEx(
|
||||
string deviceName,
|
||||
ref DeviceMode devMode,
|
||||
IntPtr handler,
|
||||
ChangeDisplaySettingsFlags flags,
|
||||
IntPtr param
|
||||
);
|
||||
|
||||
[DllImport("user32", CharSet = CharSet.Ansi)]
|
||||
public static extern ChangeDisplaySettingsExResults ChangeDisplaySettingsEx(
|
||||
string deviceName,
|
||||
IntPtr devModePointer,
|
||||
IntPtr handler,
|
||||
ChangeDisplaySettingsFlags flags,
|
||||
IntPtr param
|
||||
);
|
||||
|
||||
[DllImport("user32", CharSet = CharSet.Ansi)]
|
||||
public static extern bool EnumDisplaySettings(
|
||||
string deviceName,
|
||||
DisplaySettingsMode mode,
|
||||
ref DeviceMode devMode
|
||||
);
|
||||
|
||||
[DllImport("gdi32", CharSet = CharSet.Unicode)]
|
||||
internal static extern IntPtr CreateDC(string driver, string device, string port, IntPtr deviceMode);
|
||||
|
||||
[DllImport("gdi32")]
|
||||
internal static extern bool DeleteDC(IntPtr dcHandle);
|
||||
|
||||
|
||||
[DllImport("user32", CharSet = CharSet.Unicode)]
|
||||
internal static extern bool EnumDisplayDevices(
|
||||
string deviceName,
|
||||
uint deviceNumber,
|
||||
ref DeviceContext.Structures.DisplayDevice displayDevice,
|
||||
uint flags
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
internal static extern bool EnumDisplayMonitors(
|
||||
[In] IntPtr dcHandle,
|
||||
[In] IntPtr clip,
|
||||
MonitorEnumProcedure callback,
|
||||
IntPtr callbackObject
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
internal static extern IntPtr GetDC(IntPtr windowHandle);
|
||||
|
||||
[DllImport("gdi32")]
|
||||
internal static extern int GetDeviceCaps(DCHandle dcHandle, DeviceCapability index);
|
||||
|
||||
[DllImport("gdi32")]
|
||||
internal static extern bool GetDeviceGammaRamp(DCHandle dcHandle, ref GammaRamp ramp);
|
||||
|
||||
[DllImport("user32")]
|
||||
internal static extern bool GetMonitorInfo(
|
||||
IntPtr monitorHandle,
|
||||
ref MonitorInfo monitorInfo
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
internal static extern IntPtr MonitorFromPoint(
|
||||
[In] PointL point,
|
||||
MonitorFromFlag flag
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
internal static extern IntPtr MonitorFromRect(
|
||||
[In] RectangleL rectangle,
|
||||
MonitorFromFlag flag
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
internal static extern IntPtr MonitorFromWindow(
|
||||
[In] IntPtr windowHandle,
|
||||
MonitorFromFlag flag
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
internal static extern bool ReleaseDC([In] IntPtr windowHandle, [In] IntPtr dcHandle);
|
||||
|
||||
[DllImport("gdi32")]
|
||||
internal static extern bool SetDeviceGammaRamp(DCHandle dcHandle, ref GammaRamp ramp);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
internal delegate int MonitorEnumProcedure(
|
||||
IntPtr monitorHandle,
|
||||
IntPtr dcHandle,
|
||||
ref RectangleL rect,
|
||||
IntPtr callbackObject
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
internal enum DisplayConfigDeviceInfoType
|
||||
{
|
||||
SetSourceDPIScale = -4,
|
||||
GetSourceDPIScale = -3,
|
||||
GetSourceName = 1,
|
||||
GetTargetName = 2,
|
||||
GetTargetPreferredMode = 3,
|
||||
GetAdapterName = 4,
|
||||
SetTargetPersistence = 5,
|
||||
GetTargetBaseType = 6,
|
||||
GetSupportVirtualResolution = 7,
|
||||
SetSupportVirtualResolution = 8
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Possbile types of modes
|
||||
/// </summary>
|
||||
public enum DisplayConfigModeInfoType : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Invalid value for mode type
|
||||
/// </summary>
|
||||
Invalid = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Source mode type
|
||||
/// </summary>
|
||||
Source = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Target mode type
|
||||
/// </summary>
|
||||
Target = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Display image type
|
||||
/// </summary>
|
||||
DesktopImage = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
[Flags]
|
||||
internal enum DisplayConfigPathInfoFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
Active = 1,
|
||||
SupportVirtualMode = 8
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
[Flags]
|
||||
internal enum DisplayConfigPathSourceInfoFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
InUse = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
[Flags]
|
||||
internal enum DisplayConfigPathTargetInfoFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
InUse = 1,
|
||||
Forcible = 2,
|
||||
AvailabilityBoot = 3,
|
||||
AvailabilityPath = 4,
|
||||
AvailabilitySystem = 5
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Possible pixel formats
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553963(v=vs.85).aspx
|
||||
/// </summary>
|
||||
public enum DisplayConfigPixelFormat : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Pixel format is not specified
|
||||
/// </summary>
|
||||
NotSpecified = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates 8 bits per pixel format.
|
||||
/// </summary>
|
||||
PixelFormat8Bpp = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates 16 bits per pixel format.
|
||||
/// </summary>
|
||||
PixelFormat16Bpp = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates 24 bits per pixel format.
|
||||
/// </summary>
|
||||
PixelFormat24Bpp = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates 32 bits per pixel format.
|
||||
/// </summary>
|
||||
PixelFormat32Bpp = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the current display is not an 8, 16, 24, or 32 bits per pixel GDI desktop mode.
|
||||
/// </summary>
|
||||
PixelFormatNonGDI = 5
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Rotation modes
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553970(v=vs.85).aspx
|
||||
/// </summary>
|
||||
public enum DisplayConfigRotation : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Rotation mode is not specified
|
||||
/// </summary>
|
||||
NotSpecified = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that rotation is 0 degrees—landscape mode.
|
||||
/// </summary>
|
||||
Identity = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that rotation is 90 degrees clockwise—portrait mode.
|
||||
/// </summary>
|
||||
Rotate90 = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that rotation is 180 degrees clockwise—inverted landscape mode.
|
||||
/// </summary>
|
||||
Rotate180 = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that rotation is 270 degrees clockwise—inverted portrait mode.
|
||||
/// </summary>
|
||||
Rotate270 = 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Scaling modes
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553974(v=vs.85).aspx
|
||||
/// </summary>
|
||||
public enum DisplayConfigScaling : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Scaling mode is not specified
|
||||
/// </summary>
|
||||
NotSpecified = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
Identity = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the centering transformation; the source content is presented unscaled, centered with respect to the
|
||||
/// spatial resolution of the target mode.
|
||||
/// </summary>
|
||||
Centered = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the content is scaled to fit the path's target.
|
||||
/// </summary>
|
||||
Stretched = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the aspect-ratio centering transformation.
|
||||
/// </summary>
|
||||
AspectRatioCenteredMax = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the caller requests a custom scaling that the caller cannot describe with any of the other values.
|
||||
/// Only a hardware vendor's value-add application should use this value, because the value-add application might
|
||||
/// require a private interface to the driver. The application can then use this value to indicate additional context
|
||||
/// for the driver for the custom value on the specified path.
|
||||
/// </summary>
|
||||
Custom = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the caller does not have any preference for the scaling.
|
||||
/// </summary>
|
||||
Preferred = 128
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Possible values for display scan line ordering
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553977(v=vs.85).aspx
|
||||
/// </summary>
|
||||
public enum DisplayConfigScanLineOrdering : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that scan-line ordering of the output is unspecified.
|
||||
/// </summary>
|
||||
NotSpecified = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the output is a progressive image.
|
||||
/// </summary>
|
||||
Progressive = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the output is an interlaced image that is created beginning with the upper field.
|
||||
/// </summary>
|
||||
InterlacedWithUpperFieldFirst = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the output is an interlaced image that is created beginning with the lower field.
|
||||
/// </summary>
|
||||
InterlacedWithLowerFieldFirst = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
public enum DisplayConfigSourceDPIScale : uint
|
||||
{
|
||||
Identity = 100,
|
||||
Scale125Percent = 125,
|
||||
Scale150Percent = 150,
|
||||
Scale175Percent = 175,
|
||||
Scale200Percent = 200,
|
||||
Scale225Percent = 225,
|
||||
Scale250Percent = 250,
|
||||
Scale300Percent = 300,
|
||||
Scale350Percent = 350,
|
||||
Scale400Percent = 400,
|
||||
Scale450Percent = 450,
|
||||
Scale500Percent = 500
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
[Flags]
|
||||
internal enum DisplayConfigTargetDeviceNameFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
FriendlyNameFromEDID = 1,
|
||||
FriendlyNameForced = 2,
|
||||
EDIDIdsValid = 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Possible topology identifications
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/hardware/ff554001(v=vs.85).aspx
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum DisplayConfigTopologyId : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Invalid topology identification
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the display topology is an internal configuration.
|
||||
/// </summary>
|
||||
Internal = 0x00000001,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the display topology is clone-view configuration.
|
||||
/// </summary>
|
||||
Clone = 0x00000002,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the display topology is an extended configuration.
|
||||
/// </summary>
|
||||
Extend = 0x00000004,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the display topology is an external configuration.
|
||||
/// </summary>
|
||||
External = 0x00000008
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Possible target's connector types
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/hardware/ff554003(v=vs.85).aspx
|
||||
/// </summary>
|
||||
public enum DisplayConfigVideoOutputTechnology : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates a connector that is not one of the types that is indicated by the following enumerators in this
|
||||
/// enumeration.
|
||||
/// </summary>
|
||||
Other = 0xFFFFFFFF,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates an HD15 (VGA) connector.
|
||||
/// </summary>
|
||||
HD15 = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates an S-video connector.
|
||||
/// </summary>
|
||||
SVideo = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a composite video connector group.
|
||||
/// </summary>
|
||||
CompositeVideo = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a component video connector group.
|
||||
/// </summary>
|
||||
ComponentVideo = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a Digital Video Interface (DVI) connector.
|
||||
/// </summary>
|
||||
DVI = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a High-Definition Multimedia Interface (HDMI) connector.
|
||||
/// </summary>
|
||||
HDMI = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a Low Voltage Differential Swing (LVDS) connector.
|
||||
/// </summary>
|
||||
LVDS = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a Japanese D connector.
|
||||
/// </summary>
|
||||
DJPN = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates an SDI connector.
|
||||
/// </summary>
|
||||
SDI = 9,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates an external display port, which is a display port that connects externally to a display device.
|
||||
/// </summary>
|
||||
DisplayPortExternal = 10,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates an embedded display port that connects internally to a display device.
|
||||
/// </summary>
|
||||
DisplayPortEmbedded = 11,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates an external Unified Display Interface (UDI), which is a UDI that connects externally to a display device.
|
||||
/// </summary>
|
||||
UDIExternal = 12,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates an embedded UDI that connects internally to a display device.
|
||||
/// </summary>
|
||||
UDIEmbedded = 13,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a dongle cable that supports standard definition television (SDTV).
|
||||
/// </summary>
|
||||
SDTVDongle = 14,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the VidPN target is a Miracast wireless display device.
|
||||
/// </summary>
|
||||
Miracast = 15,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the video output device connects internally to a display device (for example, the internal
|
||||
/// connection in a laptop computer).
|
||||
/// </summary>
|
||||
Internal = 0x80000000
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Possible values for QueryDisplayConfig() flags property
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/hardware/ff569215(v=vs.85).aspx
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum QueryDeviceConfigFlags : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// All the possible path combinations of sources to targets.
|
||||
/// </summary>
|
||||
AllPaths = 0x00000001,
|
||||
|
||||
/// <summary>
|
||||
/// Currently active paths only.
|
||||
/// </summary>
|
||||
OnlyActivePaths = 0x00000002,
|
||||
|
||||
/// <summary>
|
||||
/// Active path as defined in the CCD database for the currently connected displays.
|
||||
/// </summary>
|
||||
DatabaseCurrent = 0x00000004,
|
||||
|
||||
/// <summary>
|
||||
/// Virtual Mode Aware
|
||||
/// </summary>
|
||||
VirtualModeAware = 0x0000010
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
[Flags]
|
||||
internal enum SetDisplayConfigFlags : uint
|
||||
{
|
||||
TopologyInternal = 0x00000001,
|
||||
TopologyClone = 0x00000002,
|
||||
TopologyExtend = 0x00000004,
|
||||
TopologyExternal = 0x00000008,
|
||||
UseDatabaseCurrent = TopologyInternal | TopologyClone | TopologyExtend | TopologyExternal,
|
||||
TopologySupplied = 0x00000010,
|
||||
UseSuppliedDisplayConfig = 0x00000020,
|
||||
Validate = 0x00000040,
|
||||
Apply = 0x00000080,
|
||||
NoOptimization = 0x00000100,
|
||||
SaveToDatabase = 0x00000200,
|
||||
AllowChanges = 0x00000400,
|
||||
PathPersistIfRequired = 0x00000800,
|
||||
ForceModeEnumeration = 0x00001000,
|
||||
AllowPathOrderChanges = 0x00002000,
|
||||
VirtualModeAware = 0x00008000
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553913(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfig2DRegion : IEquatable<DisplayConfig2DRegion>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Width;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Height;
|
||||
|
||||
public DisplayConfig2DRegion(uint width, uint height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfig2DRegion other)
|
||||
{
|
||||
return Width == other.Width && Height == other.Height;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfig2DRegion region && Equals(region);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((int) Width * 397) ^ (int) Height;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfig2DRegion left, DisplayConfig2DRegion right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfig2DRegion left, DisplayConfig2DRegion right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553915(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayConfigAdapterName
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public readonly string AdapterDevicePath;
|
||||
|
||||
public DisplayConfigAdapterName(LUID adapter) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/mt622102(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigDesktopImageInfo : IEquatable<DisplayConfigDesktopImageInfo>
|
||||
{
|
||||
public const ushort InvalidDesktopImageModeIndex = 0xffff;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly PointL PathSourceSize;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly RectangleL DesktopImageRegion;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly RectangleL DesktopImageClip;
|
||||
|
||||
public DisplayConfigDesktopImageInfo(
|
||||
PointL pathSourceSize,
|
||||
RectangleL desktopImageRegion,
|
||||
RectangleL desktopImageClip)
|
||||
{
|
||||
PathSourceSize = pathSourceSize;
|
||||
DesktopImageRegion = desktopImageRegion;
|
||||
DesktopImageClip = desktopImageClip;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigDesktopImageInfo other)
|
||||
{
|
||||
return PathSourceSize == other.PathSourceSize &&
|
||||
DesktopImageRegion == other.DesktopImageRegion &&
|
||||
DesktopImageClip == other.DesktopImageClip;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigDesktopImageInfo info && Equals(info);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = PathSourceSize.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ DesktopImageRegion.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ DesktopImageClip.GetHashCode();
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigDesktopImageInfo left, DisplayConfigDesktopImageInfo right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigDesktopImageInfo left, DisplayConfigDesktopImageInfo right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553920(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigDeviceInfoHeader
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigDeviceInfoType Type;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Size;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly LUID AdapterId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Id;
|
||||
|
||||
public DisplayConfigDeviceInfoHeader(LUID adapterId, Type requestType) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
Size = (uint) Marshal.SizeOf(requestType);
|
||||
|
||||
if (requestType == typeof(DisplayConfigSourceDeviceName))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetSourceName;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigTargetDeviceName))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetTargetName;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigTargetPreferredMode))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetTargetPreferredMode;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigAdapterName))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetAdapterName;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigSetTargetPersistence))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.SetTargetPersistence;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigTargetBaseType))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetTargetBaseType;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigGetSourceDPIScale))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetSourceDPIScale;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigSetSourceDPIScale))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.SetSourceDPIScale;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigSupportVirtualResolution))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// throw exception?
|
||||
}
|
||||
|
||||
public DisplayConfigDeviceInfoHeader(LUID adapterId, uint id, Type requestType) : this(adapterId, requestType)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public DisplayConfigDeviceInfoHeader(
|
||||
LUID adapterId,
|
||||
uint id,
|
||||
Type requestType,
|
||||
DisplayConfigDeviceInfoType request)
|
||||
: this(adapterId, id, requestType)
|
||||
{
|
||||
Type = request;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// Internal undocumented structure
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigGetSourceDPIScale
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
|
||||
[field: MarshalAs(UnmanagedType.U4)]
|
||||
public int MinimumScaleSteps { get; }
|
||||
|
||||
[field: MarshalAs(UnmanagedType.U4)]
|
||||
public int CurrentScaleSteps { get; }
|
||||
|
||||
[field: MarshalAs(UnmanagedType.U4)]
|
||||
public int MaximumScaleSteps { get; }
|
||||
|
||||
public DisplayConfigGetSourceDPIScale(LUID adapter, uint sourceId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, sourceId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553933(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Explicit)] // Size = 64
|
||||
internal struct DisplayConfigModeInfo : IEquatable<DisplayConfigModeInfo>
|
||||
{
|
||||
public const uint InvalidModeIndex = 0xffffffff;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(0)]
|
||||
public readonly DisplayConfigModeInfoType InfoType;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(4)]
|
||||
public readonly uint Id;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(8)]
|
||||
public readonly LUID AdapterId;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(16)]
|
||||
public readonly DisplayConfigTargetMode TargetMode;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(16)]
|
||||
public readonly DisplayConfigSourceMode SourceMode;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(16)]
|
||||
public readonly DisplayConfigDesktopImageInfo
|
||||
DesktopImageInfo;
|
||||
|
||||
public DisplayConfigModeInfo(LUID adapterId, uint id, DisplayConfigTargetMode targetMode) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
Id = id;
|
||||
TargetMode = targetMode;
|
||||
InfoType = DisplayConfigModeInfoType.Target;
|
||||
}
|
||||
|
||||
public DisplayConfigModeInfo(LUID adapterId, uint id, DisplayConfigSourceMode sourceMode) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
Id = id;
|
||||
SourceMode = sourceMode;
|
||||
InfoType = DisplayConfigModeInfoType.Source;
|
||||
}
|
||||
|
||||
public DisplayConfigModeInfo(LUID adapterId, uint id, DisplayConfigDesktopImageInfo desktopImageInfo) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
Id = id;
|
||||
DesktopImageInfo = desktopImageInfo;
|
||||
InfoType = DisplayConfigModeInfoType.DesktopImage;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigModeInfo other)
|
||||
{
|
||||
return InfoType == other.InfoType &&
|
||||
Id == other.Id &&
|
||||
AdapterId == other.AdapterId &&
|
||||
(InfoType == DisplayConfigModeInfoType.Source && SourceMode == other.SourceMode ||
|
||||
InfoType == DisplayConfigModeInfoType.Target && TargetMode == other.TargetMode ||
|
||||
InfoType == DisplayConfigModeInfoType.DesktopImage &&
|
||||
DesktopImageInfo == other.DesktopImageInfo);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigModeInfo info && Equals(info);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = (int) InfoType;
|
||||
hashCode = (hashCode * 397) ^ (int) Id;
|
||||
hashCode = (hashCode * 397) ^ AdapterId.GetHashCode();
|
||||
|
||||
switch (InfoType)
|
||||
{
|
||||
case DisplayConfigModeInfoType.Source:
|
||||
hashCode = (hashCode * 397) ^ SourceMode.GetHashCode();
|
||||
|
||||
break;
|
||||
case DisplayConfigModeInfoType.Target:
|
||||
hashCode = (hashCode * 397) ^ TargetMode.GetHashCode();
|
||||
|
||||
break;
|
||||
case DisplayConfigModeInfoType.DesktopImage:
|
||||
hashCode = (hashCode * 397) ^ DesktopImageInfo.GetHashCode();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigModeInfo left, DisplayConfigModeInfo right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigModeInfo left, DisplayConfigModeInfo right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553945(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigPathInfo
|
||||
{
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigPathSourceInfo SourceInfo;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigPathTargetInfo TargetInfo;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigPathInfoFlags Flags;
|
||||
|
||||
public DisplayConfigPathInfo(
|
||||
DisplayConfigPathSourceInfo sourceInfo,
|
||||
DisplayConfigPathTargetInfo targetInfo,
|
||||
DisplayConfigPathInfoFlags flags)
|
||||
{
|
||||
SourceInfo = sourceInfo;
|
||||
TargetInfo = targetInfo;
|
||||
Flags = flags;
|
||||
}
|
||||
|
||||
public DisplayConfigPathInfo(DisplayConfigPathSourceInfo sourceInfo, DisplayConfigPathInfoFlags flags)
|
||||
{
|
||||
SourceInfo = sourceInfo;
|
||||
Flags = flags;
|
||||
TargetInfo = new DisplayConfigPathTargetInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553951(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigPathSourceInfo
|
||||
{
|
||||
public const ushort InvalidCloneGroupId = 0xffff;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly LUID AdapterId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint SourceId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint ModeInfoIndex;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigPathSourceInfoFlags StatusFlags;
|
||||
|
||||
public ushort SourceModeInfoIndex
|
||||
{
|
||||
get => (ushort) ((ModeInfoIndex << 16) >> 16);
|
||||
}
|
||||
|
||||
public ushort CloneGroupId
|
||||
{
|
||||
get => (ushort) (ModeInfoIndex >> 16);
|
||||
}
|
||||
|
||||
public DisplayConfigPathSourceInfo(LUID adapterId, uint sourceId, uint modeInfoIndex) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
SourceId = sourceId;
|
||||
ModeInfoIndex = modeInfoIndex;
|
||||
}
|
||||
|
||||
public DisplayConfigPathSourceInfo(
|
||||
LUID adapterId,
|
||||
uint sourceId,
|
||||
ushort sourceModeInfoIndex,
|
||||
ushort cloneGroupId) : this(adapterId, sourceId, 0)
|
||||
{
|
||||
ModeInfoIndex = (uint) (sourceModeInfoIndex + (cloneGroupId << 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553954(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigPathTargetInfo
|
||||
{
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly LUID AdapterId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint TargetId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint ModeInfoIndex;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigVideoOutputTechnology OutputTechnology;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigRotation Rotation;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigScaling Scaling;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigRational RefreshRate;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigScanLineOrdering ScanLineOrdering;
|
||||
[MarshalAs(UnmanagedType.Bool)] public readonly bool TargetAvailable;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigPathTargetInfoFlags StatusFlags;
|
||||
|
||||
public ushort TargetModeInfoIndex
|
||||
{
|
||||
get => (ushort) ((ModeInfoIndex << 16) >> 16);
|
||||
}
|
||||
|
||||
public ushort DesktopModeInfoIndex
|
||||
{
|
||||
get => (ushort) (ModeInfoIndex >> 16);
|
||||
}
|
||||
|
||||
public DisplayConfigPathTargetInfo(
|
||||
LUID adapterId,
|
||||
uint targetId,
|
||||
uint modeInfoIndex,
|
||||
DisplayConfigVideoOutputTechnology outputTechnology,
|
||||
DisplayConfigRotation rotation,
|
||||
DisplayConfigScaling scaling,
|
||||
DisplayConfigRational refreshRate,
|
||||
DisplayConfigScanLineOrdering scanLineOrdering,
|
||||
bool targetAvailable) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
TargetId = targetId;
|
||||
ModeInfoIndex = modeInfoIndex;
|
||||
OutputTechnology = outputTechnology;
|
||||
Rotation = rotation;
|
||||
Scaling = scaling;
|
||||
RefreshRate = refreshRate;
|
||||
ScanLineOrdering = scanLineOrdering;
|
||||
TargetAvailable = targetAvailable;
|
||||
}
|
||||
|
||||
public DisplayConfigPathTargetInfo(
|
||||
LUID adapterId,
|
||||
uint targetId,
|
||||
ushort targetModeInfoIndex,
|
||||
ushort desktopModeInfoIndex,
|
||||
DisplayConfigVideoOutputTechnology outputTechnology,
|
||||
DisplayConfigRotation rotation,
|
||||
DisplayConfigScaling scaling,
|
||||
DisplayConfigRational refreshRate,
|
||||
DisplayConfigScanLineOrdering scanLineOrdering,
|
||||
bool targetAvailable)
|
||||
: this(
|
||||
adapterId, targetId, 0, outputTechnology, rotation, scaling, refreshRate, scanLineOrdering,
|
||||
targetAvailable)
|
||||
{
|
||||
ModeInfoIndex = (uint) (targetModeInfoIndex + (desktopModeInfoIndex << 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553968(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigRational : IEquatable<DisplayConfigRational>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Numerator;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Denominator;
|
||||
|
||||
public DisplayConfigRational(uint numerator, uint denominator, bool simplify)
|
||||
: this((ulong) numerator, denominator, simplify)
|
||||
{
|
||||
}
|
||||
|
||||
public DisplayConfigRational(ulong numerator, ulong denominator, bool simplify)
|
||||
{
|
||||
var gcm = simplify & (numerator != 0) ? Euclidean(numerator, denominator) : 1;
|
||||
Numerator = (uint) (numerator / gcm);
|
||||
Denominator = (uint) (denominator / gcm);
|
||||
}
|
||||
|
||||
private static ulong Euclidean(ulong a, ulong b)
|
||||
{
|
||||
while (a != 0 && b != 0)
|
||||
{
|
||||
if (a > b)
|
||||
{
|
||||
a %= b;
|
||||
}
|
||||
else
|
||||
{
|
||||
b %= a;
|
||||
}
|
||||
}
|
||||
|
||||
return a == 0 ? b : a;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public ulong ToValue(ulong multiplier = 1)
|
||||
{
|
||||
if (Numerator == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Numerator * multiplier / Denominator;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigRational other)
|
||||
{
|
||||
if (Numerator == other.Numerator && Denominator == other.Denominator)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var left = Numerator / (double) Denominator;
|
||||
var right = other.Numerator / (double) other.Denominator;
|
||||
|
||||
return Math.Abs(left - right) <= Math.Max(Math.Abs(left), Math.Abs(right)) * 1E-15;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigRational rational && Equals(rational);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((int) Numerator * 397) ^ (int) Denominator;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigRational left, DisplayConfigRational right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigRational left, DisplayConfigRational right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// Internal undocumented structure
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigSetSourceDPIScale
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
|
||||
[field: MarshalAs(UnmanagedType.U4)]
|
||||
public int ScaleSteps { get; }
|
||||
|
||||
public DisplayConfigSetSourceDPIScale(LUID adapter, uint sourceId, int scaleSteps) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, sourceId, GetType());
|
||||
ScaleSteps = scaleSteps;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553981(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigSetTargetPersistence
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] private readonly uint _BootPersistenceOn;
|
||||
|
||||
public bool BootPersistence
|
||||
{
|
||||
get => _BootPersistenceOn > 0;
|
||||
}
|
||||
|
||||
public DisplayConfigSetTargetPersistence(LUID adapter, uint targetId, bool bootPersistence) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType());
|
||||
_BootPersistenceOn = bootPersistence ? 1u : 0u;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553983(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayConfigSourceDeviceName
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||
public readonly string DeviceName;
|
||||
|
||||
public DisplayConfigSourceDeviceName(LUID adapter, uint sourceId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, sourceId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553986(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigSourceMode : IEquatable<DisplayConfigSourceMode>
|
||||
{
|
||||
public const ushort InvalidSourceModeIndex = 0xffff;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Width;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Height;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigPixelFormat PixelFormat;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly PointL Position;
|
||||
|
||||
public DisplayConfigSourceMode(uint width, uint height, DisplayConfigPixelFormat pixelFormat, PointL position)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
PixelFormat = pixelFormat;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigSourceMode other)
|
||||
{
|
||||
return Width == other.Width &&
|
||||
Height == other.Height &&
|
||||
PixelFormat == other.PixelFormat &&
|
||||
Position == other.Position;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigSourceMode mode && Equals(mode);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = (int) Width;
|
||||
hashCode = (hashCode * 397) ^ (int) Height;
|
||||
hashCode = (hashCode * 397) ^ (int) PixelFormat;
|
||||
hashCode = (hashCode * 397) ^ Position.GetHashCode();
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigSourceMode left, DisplayConfigSourceMode right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigSourceMode left, DisplayConfigSourceMode right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/mt622103(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayConfigSupportVirtualResolution
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] private readonly int _DisableMonitorVirtualResolution;
|
||||
|
||||
public bool DisableMonitorVirtualResolution
|
||||
{
|
||||
get => _DisableMonitorVirtualResolution > 0;
|
||||
}
|
||||
|
||||
public DisplayConfigSupportVirtualResolution(LUID adapter, uint targetId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType(),
|
||||
DisplayConfigDeviceInfoType.GetSupportVirtualResolution);
|
||||
}
|
||||
|
||||
public DisplayConfigSupportVirtualResolution(LUID adapter, uint targetId, bool disableMonitorVirtualResolution)
|
||||
: this()
|
||||
{
|
||||
_DisableMonitorVirtualResolution = disableMonitorVirtualResolution ? 1 : 0;
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType(),
|
||||
DisplayConfigDeviceInfoType.SetSupportVirtualResolution);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/dn362043(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigTargetBaseType
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigVideoOutputTechnology BaseOutputTechnology;
|
||||
|
||||
public DisplayConfigTargetBaseType(LUID adapter, uint targetId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553989(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayConfigTargetDeviceName
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigTargetDeviceNameFlags Flags;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigVideoOutputTechnology OutputTechnology;
|
||||
[MarshalAs(UnmanagedType.U2)] public readonly ushort EDIDManufactureId;
|
||||
[MarshalAs(UnmanagedType.U2)] public readonly ushort EDIDProductCodeId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint ConnectorInstance;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
||||
public readonly string MonitorFriendlyDeviceName;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public readonly string MonitorDevicePath;
|
||||
|
||||
|
||||
public DisplayConfigTargetDeviceName(LUID adapter, uint targetId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553993(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigTargetMode : IEquatable<DisplayConfigTargetMode>
|
||||
{
|
||||
public const ushort InvalidTargetModeIndex = 0xffff;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigVideoSignalInfo TargetVideoSignalInfo;
|
||||
|
||||
public DisplayConfigTargetMode(DisplayConfigVideoSignalInfo targetVideoSignalInfo)
|
||||
{
|
||||
TargetVideoSignalInfo = targetVideoSignalInfo;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigTargetMode other)
|
||||
{
|
||||
return TargetVideoSignalInfo == other.TargetVideoSignalInfo;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigTargetMode mode && Equals(mode);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return TargetVideoSignalInfo.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigTargetMode left, DisplayConfigTargetMode right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigTargetMode left, DisplayConfigTargetMode right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553996(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigTargetPreferredMode
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Width;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Height;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigTargetMode TargetMode;
|
||||
|
||||
public DisplayConfigTargetPreferredMode(LUID adapter, uint targetId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff554007(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigVideoSignalInfo : IEquatable<DisplayConfigVideoSignalInfo>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U8)] public readonly ulong PixelRate;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigRational HorizontalSyncFrequency;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigRational VerticalSyncFrequency;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfig2DRegion ActiveSize;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfig2DRegion TotalSize;
|
||||
[MarshalAs(UnmanagedType.U2)] public readonly VideoSignalStandard VideoStandard;
|
||||
[MarshalAs(UnmanagedType.U2)] public readonly ushort VerticalSyncFrequencyDivider;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigScanLineOrdering ScanLineOrdering;
|
||||
|
||||
public DisplayConfigVideoSignalInfo(
|
||||
ulong pixelRate,
|
||||
DisplayConfigRational horizontalSyncFrequency,
|
||||
DisplayConfigRational verticalSyncFrequency,
|
||||
DisplayConfig2DRegion activeSize,
|
||||
DisplayConfig2DRegion totalSize,
|
||||
VideoSignalStandard videoStandard,
|
||||
ushort verticalSyncFrequencyDivider,
|
||||
DisplayConfigScanLineOrdering scanLineOrdering)
|
||||
{
|
||||
PixelRate = pixelRate;
|
||||
HorizontalSyncFrequency = horizontalSyncFrequency;
|
||||
VerticalSyncFrequency = verticalSyncFrequency;
|
||||
ActiveSize = activeSize;
|
||||
TotalSize = totalSize;
|
||||
VideoStandard = videoStandard;
|
||||
VerticalSyncFrequencyDivider = verticalSyncFrequencyDivider;
|
||||
ScanLineOrdering = scanLineOrdering;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigVideoSignalInfo other)
|
||||
{
|
||||
return PixelRate == other.PixelRate &&
|
||||
HorizontalSyncFrequency == other.HorizontalSyncFrequency &&
|
||||
VerticalSyncFrequency == other.VerticalSyncFrequency &&
|
||||
ActiveSize == other.ActiveSize &&
|
||||
TotalSize == other.TotalSize &&
|
||||
VideoStandard == other.VideoStandard &&
|
||||
VerticalSyncFrequencyDivider == other.VerticalSyncFrequencyDivider &&
|
||||
ScanLineOrdering == other.ScanLineOrdering;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigVideoSignalInfo info && Equals(info);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = PixelRate.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ HorizontalSyncFrequency.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ VerticalSyncFrequency.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ ActiveSize.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ TotalSize.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ (int) VideoStandard;
|
||||
hashCode = (hashCode * 397) ^ VerticalSyncFrequencyDivider.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ (int) ScanLineOrdering;
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigVideoSignalInfo left, DisplayConfigVideoSignalInfo right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigVideoSignalInfo left, DisplayConfigVideoSignalInfo right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Possible video signal standards
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/hardware/ff546632(v=vs.85).aspx
|
||||
/// </summary>
|
||||
public enum VideoSignalStandard : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that the variable has not yet been assigned a meaningful value.
|
||||
/// </summary>
|
||||
Uninitialized = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the Video Electronics Standards Association (VESA) Display Monitor Timing (DMT) standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
VESA_DMT = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the VESA Generalized Timing Formula (GTF) standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
VESA_GTF = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the VESA Coordinated Video Timing (CVT) standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
VESA_CVT = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the IBM standard.
|
||||
/// </summary>
|
||||
IBM = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the Apple standard.
|
||||
/// </summary>
|
||||
Apple = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the National Television Standards Committee (NTSC) standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
NTSC_M = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the NTSC japanese standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
NTSC_J = 7,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the NTSC standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
NTSC_443 = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the Phase Alteration Line (PAL) standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_B = 9,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_B1 = 10,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_G = 11,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_H = 12,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_I = 13,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_D = 14,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_N = 15,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_NC = 16,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the Systeme Electronic Pour Couleur Avec Memoire (SECAM) standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SECAM_B = 17,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the SECAM standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SECAM_D = 18,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the SECAM standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SECAM_G = 19,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the SECAM standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SECAM_H = 20,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the SECAM standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SECAM_K = 21,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the SECAM standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SECAM_K1 = 22,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the SECAM standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SECAM_L = 23,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the SECAM standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
SECAM_L1 = 24,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the Electronics Industries Association (EIA) standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
EIA_861 = 25,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the EIA standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
EIA_861A = 26,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the EIA standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
EIA_861B = 27,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_K = 28,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_K1 = 29,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_L = 30,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the PAL standard.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
PAL_M = 31,
|
||||
|
||||
/// <summary>
|
||||
/// Represents any video standard other than those represented by the previous constants in this enumeration.
|
||||
/// </summary>
|
||||
Other = 255
|
||||
}
|
||||
}
|
||||
96
app/WindowsDisplayAPI/Native/DisplayConfigApi.cs
Normal file
96
app/WindowsDisplayAPI/Native/DisplayConfigApi.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.DisplayConfig;
|
||||
using WindowsDisplayAPI.Native.DisplayConfig.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native
|
||||
{
|
||||
internal class DisplayConfigApi
|
||||
{
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigGetDeviceInfo(
|
||||
ref DisplayConfigSupportVirtualResolution targetSupportVirtualResolution
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigGetDeviceInfo(
|
||||
ref DisplayConfigGetSourceDPIScale targetSupportVirtualResolution
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigGetDeviceInfo(
|
||||
ref DisplayConfigTargetDeviceName deviceName
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigGetDeviceInfo(
|
||||
ref DisplayConfigAdapterName deviceName
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigGetDeviceInfo(
|
||||
ref DisplayConfigSourceDeviceName deviceName
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigGetDeviceInfo(
|
||||
ref DisplayConfigTargetPreferredMode targetPreferredMode
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigGetDeviceInfo(
|
||||
ref DisplayConfigTargetBaseType targetBaseType
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigSetDeviceInfo(
|
||||
ref DisplayConfigSetTargetPersistence targetPersistence
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigSetDeviceInfo(
|
||||
ref DisplayConfigSupportVirtualResolution targetSupportVirtualResolution
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status DisplayConfigSetDeviceInfo(
|
||||
ref DisplayConfigSetSourceDPIScale setSourceDpiScale
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status GetDisplayConfigBufferSizes(
|
||||
QueryDeviceConfigFlags flags,
|
||||
out uint pathArrayElements,
|
||||
out uint modeInfoArrayElements
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status QueryDisplayConfig(
|
||||
QueryDeviceConfigFlags flags,
|
||||
ref uint pathArrayElements,
|
||||
[Out] DisplayConfigPathInfo[] pathInfoArray,
|
||||
ref uint modeInfoArrayElements,
|
||||
[Out] DisplayConfigModeInfo[] modeInfoArray,
|
||||
IntPtr currentTopologyId
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status QueryDisplayConfig(
|
||||
QueryDeviceConfigFlags flags,
|
||||
ref uint pathArrayElements,
|
||||
[Out] DisplayConfigPathInfo[] pathInfoArray,
|
||||
ref uint modeInfoArrayElements,
|
||||
[Out] DisplayConfigModeInfo[] modeInfoArray,
|
||||
[Out] out DisplayConfigTopologyId currentTopologyId
|
||||
);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern Win32Status SetDisplayConfig(
|
||||
[In] uint pathArrayElements,
|
||||
[In] DisplayConfigPathInfo[] pathInfoArray,
|
||||
[In] uint modeInfoArrayElements,
|
||||
[In] DisplayConfigModeInfo[] modeInfoArray,
|
||||
[In] SetDisplayConfigFlags flags
|
||||
);
|
||||
}
|
||||
}
|
||||
104
app/WindowsDisplayAPI/Native/Structures/LUID.cs
Normal file
104
app/WindowsDisplayAPI/Native/Structures/LUID.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.Structures
|
||||
{
|
||||
/// <summary>
|
||||
/// Locally unique identifier is a 64-bit value guaranteed to be unique only on the system on which it was generated.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct LUID : IEquatable<LUID>
|
||||
{
|
||||
/// <summary>
|
||||
/// 32Bit unsigned integer, low
|
||||
/// </summary>
|
||||
public readonly uint LowPart;
|
||||
|
||||
/// <summary>
|
||||
/// 32Bit signed integer, high
|
||||
/// </summary>
|
||||
public readonly int HighPart;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new LUID
|
||||
/// </summary>
|
||||
/// <param name="lowPart">32Bit unsigned integer, low</param>
|
||||
/// <param name="highPart">32Bit signed integer, high</param>
|
||||
public LUID(uint lowPart, int highPart)
|
||||
{
|
||||
LowPart = lowPart;
|
||||
HighPart = highPart;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ {LowPart:X} - {HighPart:X} }}";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(LUID other)
|
||||
{
|
||||
return LowPart == other.LowPart && HighPart == other.HighPart;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is LUID luid && Equals(luid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks for equality between two objects of same type
|
||||
/// </summary>
|
||||
/// <param name="left">The first object</param>
|
||||
/// <param name="right">The second object</param>
|
||||
/// <returns>true, if both objects are equal, otherwise false</returns>
|
||||
public static bool operator ==(LUID left, LUID right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks for inequality between two objects of same type
|
||||
/// </summary>
|
||||
/// <param name="left">The first object</param>
|
||||
/// <param name="right">The second object</param>
|
||||
/// <returns>true, if both objects are not equal, otherwise false</returns>
|
||||
public static bool operator !=(LUID left, LUID right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((int) LowPart * 397) ^ HighPart;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this type is empty and holds no real data
|
||||
/// </summary>
|
||||
/// <returns>true if empty, otherwise false</returns>
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return LowPart == 0 && HighPart == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an empty instance of this type
|
||||
/// </summary>
|
||||
public static LUID Empty
|
||||
{
|
||||
get => default;
|
||||
}
|
||||
}
|
||||
}
|
||||
74
app/WindowsDisplayAPI/Native/Structures/PointL.cs
Normal file
74
app/WindowsDisplayAPI/Native/Structures/PointL.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/dd162807(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct PointL : IEquatable<PointL>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.I4)] public readonly int X;
|
||||
[MarshalAs(UnmanagedType.I4)] public readonly int Y;
|
||||
|
||||
[Pure]
|
||||
public Point ToPoint()
|
||||
{
|
||||
return new Point(X, Y);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public Size ToSize()
|
||||
{
|
||||
return new Size(X, Y);
|
||||
}
|
||||
|
||||
public PointL(Point point) : this(point.X, point.Y)
|
||||
{
|
||||
}
|
||||
|
||||
public PointL(Size size) : this(size.Width, size.Height)
|
||||
{
|
||||
}
|
||||
|
||||
public PointL(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public bool Equals(PointL other)
|
||||
{
|
||||
return X == other.X && Y == other.Y;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is PointL point && Equals(point);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (X * 397) ^ Y;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(PointL left, PointL right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(PointL left, PointL right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
app/WindowsDisplayAPI/Native/Structures/RectangleL.cs
Normal file
73
app/WindowsDisplayAPI/Native/Structures/RectangleL.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/dd162907(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct RectangleL : IEquatable<RectangleL>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly int Left;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly int Top;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly int Right;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly int Bottom;
|
||||
|
||||
[Pure]
|
||||
public Rectangle ToRectangle()
|
||||
{
|
||||
return new Rectangle(Left, Top, Right - Left, Bottom - Top);
|
||||
}
|
||||
|
||||
public RectangleL(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
public RectangleL(Rectangle rectangle) : this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom)
|
||||
{
|
||||
}
|
||||
|
||||
public bool Equals(RectangleL other)
|
||||
{
|
||||
return Left == other.Left && Top == other.Top && Right == other.Right && Bottom == other.Bottom;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is RectangleL rectangle && Equals(rectangle);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = Left;
|
||||
hashCode = (hashCode * 397) ^ Top;
|
||||
hashCode = (hashCode * 397) ^ Right;
|
||||
hashCode = (hashCode * 397) ^ Bottom;
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(RectangleL left, RectangleL right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(RectangleL left, RectangleL right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
app/WindowsDisplayAPI/Native/Win32Status.cs
Normal file
8
app/WindowsDisplayAPI/Native/Win32Status.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace WindowsDisplayAPI.Native
|
||||
{
|
||||
internal enum Win32Status
|
||||
{
|
||||
Success = 0x0,
|
||||
ErrorInsufficientBuffer = 0x7A
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user