From 0da5925a082a8ccc9992f83d962fc0e5a8653ff5 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Fri, 12 Feb 2021 20:10:48 -0800 Subject: [PATCH] Add Win32API Extern class; using User32.dll for display resolution, refresh rate, and more --- src/Extern/User32.cs | 62 ++++++++++++++++++++++++++++++++++++++++++++ src/SPV3.csproj | 1 + 2 files changed, 63 insertions(+) create mode 100644 src/Extern/User32.cs diff --git a/src/Extern/User32.cs b/src/Extern/User32.cs new file mode 100644 index 00000000..72cd30d4 --- /dev/null +++ b/src/Extern/User32.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace SPV3.Extern +{ + // original code shamelessly borrowed from https://stackoverflow.com/a/744609/14894786 + public class User32 + { + [DllImport("user32.dll")] + public static extern bool EnumDisplaySettings( + string deviceName, + int modeNum, + ref DEVMODE devMode); + const int ENUM_CURRENT_SETTINGS = -1; + const int ENUM_REGISTRY_SETTINGS = -2; + + [StructLayout(LayoutKind.Sequential)] + public struct DEVMODE + { + + private const int CCHDEVICENAME = 0x20; + private const int CCHFORMNAME = 0x20; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)] + public string dmDeviceName; + public short dmSpecVersion; + public short dmDriverVersion; + public short dmSize; + public short dmDriverExtra; + public int dmFields; + public int dmPositionX; + public int dmPositionY; + public ScreenOrientation dmDisplayOrientation; + public int dmDisplayFixedOutput; + public short dmColor; + public short dmDuplex; + public short dmYResolution; + public short dmTTOption; + public short dmCollate; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)] + public string dmFormName; + public short dmLogPixels; + public int dmBitsPerPel; + public int dmPelsWidth; + public int dmPelsHeight; + public int dmDisplayFlags; + public int dmDisplayFrequency; + public int dmICMMethod; + public int dmICMIntent; + public int dmMediaType; + public int dmDitherType; + public int dmReserved1; + public int dmReserved2; + public int dmPanningWidth; + public int dmPanningHeight; + } + } +} diff --git a/src/SPV3.csproj b/src/SPV3.csproj index 158c7108..bb91bbf4 100644 --- a/src/SPV3.csproj +++ b/src/SPV3.csproj @@ -98,6 +98,7 @@ ControllerPreset.xaml + Information.UserControl.xaml