Beispiel #1
0
 internal static extern int EnumDisplaySettings(
     string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
Beispiel #2
0
        public static bool Rotate(uint DisplayNumber, Orientations Orientation)
        {
            if (DisplayNumber == 0)
            {
                throw new ArgumentOutOfRangeException("DisplayNumber", DisplayNumber, "First display is 1.");
            }

            bool result = false;
//            DISPLAY_DEVICE d = new DISPLAY_DEVICE();
            DEVMODE dm = new DEVMODE();
//            d.cb = Marshal.SizeOf(d);

//            if (!NativeMethods.EnumDisplayDevices(null, DisplayNumber - 1, ref d, 0))
//                throw new ArgumentOutOfRangeException("DisplayNumber", DisplayNumber, "Number is greater than connected displays.");

            var displays = Display.GetDisplays().ToArray();
            var display  = displays[DisplayNumber - 1];

            if (0 != NativeMethods.EnumDisplaySettings(
                    display.DisplayName, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
            {
                if ((dm.dmDisplayOrientation + (int)Orientation) % 2 == 1) // Need to swap height and width?
                {
                    int temp = dm.dmPelsHeight;
                    dm.dmPelsHeight = dm.dmPelsWidth;
                    dm.dmPelsWidth  = temp;
                }

                switch (Orientation)
                {
                case Orientations.DEGREES_CW_90:
                    dm.dmDisplayOrientation = NativeMethods.DMDO_270;
                    break;

                case Orientations.DEGREES_CW_180:
                    dm.dmDisplayOrientation = NativeMethods.DMDO_180;
                    break;

                case Orientations.DEGREES_CW_270:
                    dm.dmDisplayOrientation = NativeMethods.DMDO_90;
                    break;

                case Orientations.DEGREES_CW_0:
                    dm.dmDisplayOrientation = NativeMethods.DMDO_DEFAULT;
                    break;

                default:
                    break;
                }

                DISP_CHANGE ret = NativeMethods.ChangeDisplaySettingsEx(
                    display.DisplayName, ref dm, IntPtr.Zero,
                    DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);

                result = ret == 0;
            }



            return(result);
        }
Beispiel #3
0
 internal static extern DISP_CHANGE ChangeDisplaySettingsEx(
     string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd,
     DisplaySettingsFlags dwflags, IntPtr lParam);