/// <summary> /// 修改屏幕分辨 /// </summary> /// <param name="i"></param> public static Boolean ChangeScreen(int width, int height) { DEVMODE dm = new DEVMODE(); dm.dmDeviceName = new string(new char[32]); dm.dmFormName = new string(new char[32]); dm.dmSize = (short)Marshal.SizeOf(dm); if (0 != EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref dm)) { if (dm.dmPelsHeight == height && dm.dmPelsWidth == width) { return(false); } dm.dmPelsHeight = height; dm.dmPelsWidth = width; int iRet = ChangeDisplaySettings(ref dm, 0); return(true); } return(false); }
public static extern int ChangeDisplaySettings(ref DEVMODE lpDevMode, int dwFlags);
public static extern int ChangeDisplaySettingsEx(string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, int dwflags, IntPtr lParam);
public static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
private static void CommitChange(Screen screen) { DEVMODE ndm5 = CreateDevmode(); ChangeDisplaySettingsEx(screen.DeviceName, ref ndm5, (IntPtr)null, (int)(DeviceFlags.CDS_UPDATEREGISTRY), (IntPtr)null); }