private static void ChangeSettings(DEVMODE dm) { // helper to wrap ChangeDisplaySettings Win32 API var iRet = NativeMethods.ChangeDisplaySettings(ref dm, 0); switch (iRet) { case NativeMethods.DISP_CHANGE_SUCCESSFUL: break; case NativeMethods.DISP_CHANGE_RESTART: Console.WriteLine("Please restart your system"); break; case NativeMethods.DISP_CHANGE_FAILED: Console.WriteLine("ChangeDisplaySettigns API failed"); break; case NativeMethods.DISP_CHANGE_BADDUALVIEW: Console.WriteLine("The settings change was unsuccessful because system is DualView capable."); break; case NativeMethods.DISP_CHANGE_BADFLAGS: Console.WriteLine("An invalid set of flags was passed in."); break; case NativeMethods.DISP_CHANGE_BADPARAM: Console.WriteLine("An invalid parameter was passed in. This can include an invalid flag or combination of flags."); break; case NativeMethods.DISP_CHANGE_NOTUPDATED: Console.WriteLine("Unable to write settings to the registry."); break; default: Console.WriteLine("Unknown return value from ChangeDisplaySettings API"); break; } }
// helper for creating an initialized DEVMODE structure public static DEVMODE CreateDevmode() { DEVMODE dm = new DEVMODE(); dm.dmDeviceName = new String(new char[32]); dm.dmFormName = new String(new char[32]); dm.dmSize = (short)Marshal.SizeOf(dm); return dm; }
private static int GetSettings(ref DEVMODE dm, int iModeNum) { // helper to wrap EnumDisplaySettings Win32 API return NativeMethods.EnumDisplaySettings(null, iModeNum, ref dm); }
private static int GetSettings(ref DEVMODE dm) { // helper to obtain current settings return GetSettings(ref dm, NativeMethods.ENUM_CURRENT_SETTINGS); }
public static extern int ChangeDisplaySettings(ref DEVMODE lpDevMode, int dwFlags);
public static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);