|
|
- using System;
- using System.Runtime.InteropServices;
- class Program
- {
- [DllImport("user32.dll")]
- static extern bool ChangeDisplaySettingsEx(string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, uint dwflags, IntPtr lParam);
- [StructLayout(LayoutKind.Sequential)]
- struct DEVMODE
- {
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
- 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 dmColorBits;
- public short dmCopies;
- public short dmDefaultSource;
- public short dmPrintQuality;
- 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;
- }
- const int CDS_UPDATEREGISTRY = 0x01;
- const int CDS_TEST = 0x04;
- const int DISP_CHANGE_SUCCESSFUL = 0;
- static void Main(string[] args)
- {
- DEVMODE devMode = new DEVMODE();
- devMode.dmDeviceName = new String(' ', 32);
- devMode.dmSpecVersion = 0x0300;
- devMode.dmSize = (short)Marshal.SizeOf(devMode);
- devMode.dmPanningWidth = devMode.dmPositionX = devMode.dmDisplayFrequency = 0;
- devMode.dmPanningHeight = devMode.dmPositionY = 0;
- devMode.dmFields = 0x00080000 | 0x00100000; // DM_PELSWIDTH | DM_PELSHEIGHT
- devMode.dmPanningWidth = devMode.dmPositionX = 1440; // 分辨率宽度
- devMode.dmPanningHeight = devMode.dmPositionY = 900; // 分辨率高度
- int result = ChangeDisplaySettingsEx(null, ref devMode, IntPtr.Zero, CDS_TEST, IntPtr.Zero);
- if (result == DISP_CHANGE_SUCCESSFUL)
- {
- result = ChangeDisplaySettingsEx(null, ref devMode, IntPtr.Zero, CDS_UPDATEREGISTRY, IntPtr.Zero);
- }
- Console.WriteLine("分辨率已尝试设置为 1440x900");
- }
- }
复制代码
|
评分
-
查看全部评分
|