73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace LANCommander.PowerShell.Extensions
|
|
{
|
|
public static class ScreenExtensions
|
|
{
|
|
public static DEVMODE GetDeviceMode(this Screen screen)
|
|
{
|
|
DEVMODE devMode = new DEVMODE();
|
|
devMode.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
|
|
EnumDisplaySettings(screen.DeviceName, ENUM_CURRENT_SETTINGS, ref devMode);
|
|
return devMode;
|
|
}
|
|
|
|
[DllImport("user32.dll")]
|
|
private static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
|
|
|
|
private const int ENUM_CURRENT_SETTINGS = -1;
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct DEVMODE
|
|
{
|
|
private const int CCHDEVICENAME = 32;
|
|
private const int CCHFORMNAME = 32;
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
|
|
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 int dmDisplayOrientation;
|
|
public int dmDisplayFixedOutput;
|
|
|
|
public short dmColor;
|
|
public short dmDuplex;
|
|
public short dmYResolution;
|
|
public short dmTTOption;
|
|
public short dmCollate;
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
|
|
public string dmFormName;
|
|
|
|
public short dmLogPixels;
|
|
public int dmBitsPerPel;
|
|
public int dmPelsWidth;
|
|
public int dmPelsHeight;
|
|
public int dmDisplayFlags;
|
|
public int dmNup;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|