Ejemplo n.º 1
0
 public static extern int ChangeDisplaySettings(
     [In, Out]
     ref DEVMODE lpDevMode,
     [param: MarshalAs(UnmanagedType.U4)]
     uint dwflags);
Ejemplo n.º 2
0
        public static void RotateScreen(bool clockwise)
        {
            DEVMODE originalMode = new DEVMODE();

            originalMode.dmSize =
                (ushort)Marshal.SizeOf(originalMode);

            EnumDisplaySettings(null, -1, ref originalMode);

            // Making a copy of the current settings
            // to allow reseting to the original mode
            DEVMODE newMode = originalMode;

            // Rotating the screen
            if (clockwise)
            {
                if (newMode.dmDisplayOrientation < 3)
                {
                    newMode.dmDisplayOrientation++;
                }
                else
                {
                    newMode.dmDisplayOrientation = 0;
                }
            }

            // Swapping width and height;
            uint temp = newMode.dmPelsWidth;

            newMode.dmPelsWidth  = newMode.dmPelsHeight;
            newMode.dmPelsHeight = temp;

            // Capturing the operation result
            // Capturing the operation result
            int result =
                ChangeDisplaySettings(ref newMode, 0);

            if (result == 0)
            {
                // Inspecting the new mode
                GetCurrentSettings();

                Console.WriteLine();

                // Waiting for seeing the results
                Console.ReadKey(true);

                ChangeDisplaySettings(ref originalMode, 0);
            }
            else if (result == -2)
            {
                Console.WriteLine("Mode not supported.");
            }
            else if (result == 1)
            {
                Console.WriteLine("Restart required.");
            }
            else
            {
                Console.WriteLine("Failed. Error code = {0}", result);
            }
        }
Ejemplo n.º 3
0
 public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);