Ejemplo n.º 1
0
        // helper for creating an initialized DEVMODE structure
        public static Devmode CreateDevmode()
        {
            var dm = new Devmode {
                dmDeviceName = new String(new char[32]), dmFormName = new String(new char[32])
            };

            dm.dmSize = (short)Marshal.SizeOf(dm);
            return(dm);
        }
Ejemplo n.º 2
0
        private static void ChangeSettings(Devmode dm)
        {
            // helper to wrap ChangeDisplaySettings Win32 API

            var iRet = NativeMethods.ChangeDisplaySettings(ref dm, 0);

            switch (iRet)
            {
            case NativeMethods.DispChangeSuccessful:
                break;

            case NativeMethods.DispChangeRestart:
                Console.WriteLine("Please restart your system");
                break;

            case NativeMethods.DispChangeFailed:
                Console.WriteLine("ChangeDisplaySettigns API failed");
                break;

            case NativeMethods.DispChangeBaddualview:
                Console.WriteLine("The settings change was unsuccessful because system is DualView capable.");
                break;

            case NativeMethods.DispChangeBadflags:
                Console.WriteLine("An invalid set of flags was passed in.");
                break;

            case NativeMethods.DispChangeBadparam:
                Console.WriteLine(
                    "An invalid parameter was passed in. This can include an invalid flag or combination of flags.");
                break;

            case NativeMethods.DispChangeNotupdated:
                Console.WriteLine("Unable to write settings to the registry.");
                break;

            default:
                Console.WriteLine("Unknown return value from ChangeDisplaySettings API");
                break;
            }
        }
Ejemplo n.º 3
0
 public static extern int ChangeDisplaySettings(ref Devmode lpDevMode, int dwFlags);
Ejemplo n.º 4
0
 public static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref Devmode lpDevMode);
Ejemplo n.º 5
0
 private static void GetSettings(ref Devmode dm, int iModeNum)
 {
     // helper to wrap EnumDisplaySettings Win32 API
     NativeMethods.EnumDisplaySettings(null, iModeNum, ref dm);
 }
Ejemplo n.º 6
0
 private static void GetSettings(ref Devmode dm)
 {
     // helper to obtain current settings
     GetSettings(ref dm, NativeMethods.EnumCurrentSettings);
 }