Example #1
0
        public static ScreenEx GetScreenSettings(Forms.Screen screen)
        {
            ScreenSettingsDevMode DevMode = new ScreenSettingsDevMode(true);

            if (EnumDisplaySettings(screen.DeviceName, -1 /*current settings*/, ref DevMode) == 0)
            {
                throw new Exception("EnumDisplaySettings (user32.dll) returned 0");
            }
            ScreenEx screenSettings = new ScreenEx(screen, DevMode);

            return(screenSettings);
        }
Example #2
0
        /// <summary>
        /// <para>Updates the screen's settings</para>
        /// </summary>
        /// <param name="screen"></param>
        /// <returns></returns>
        public static bool UpdateScreen(ScreenEx screen)
        {
            ScreenSettingsDevMode devMode = screen.ToDEVMODE();
            DispChange            result  = ChangeDisplaySettingsEx(screen.Name, ref devMode, CDS.RESET | CDS.UPDATEREGISTRY);

            if (result >= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
 public ScreenEx(Forms.Screen screen, ScreenSettingsDevMode devMode)
 {
     this.DeviceName    = screen.DeviceName;
     this.BitsPerPixel  = (byte)screen.BitsPerPixel;
     this.Bounds        = new Rectangle(screen.Bounds.Location, screen.Bounds.Size);
     this.Primary       = screen.Primary;
     this.SpecVersion   = devMode.dmSpecVersion;
     this.DriverVersion = devMode.dmDriverVersion;
     this.FixedOutput   = (FixedOutput)devMode.dmDisplayFixedOutput;
     this.LogPixels     = devMode.dmLogPixels;
     this.ColorDepth    = (ColorDepth)devMode.dmBitsPerPel;
     this.DisplayFlags  = devMode.dmDisplayFlags;
     this.Frequency     = (byte)devMode.dmDisplayFrequency;
     this.Orientation   = (ScreenOrientation)devMode.dmDisplayOrientation;
     this.fields        = 0;
 }
Example #4
0
        /// <summary>
        /// <para>Converts this class to a <see cref="ScreenSettingsDevMode"/> struct which then may be used to update the settings</para>
        /// </summary>
        /// <returns></returns>
        public ScreenSettingsDevMode ToDEVMODE()
        {
            ScreenSettingsDevMode devMode = new ScreenSettingsDevMode(true);

            devMode.dmBitsPerPel         = this.BitsPerPixel;
            devMode.dmDeviceName         = this.DeviceName;
            devMode.dmDisplayFixedOutput = (int)this.FixedOutput;
            devMode.dmDisplayFlags       = this.DisplayFlags;
            devMode.dmDisplayFrequency   = this.Frequency;
            devMode.dmDisplayOrientation = (int)this.Orientation;
            devMode.dmDriverVersion      = this.DriverVersion;
            devMode.dmFields             = (int)this.fields;
            devMode.dmFormName           = "";
            devMode.dmLogPixels          = this.LogPixels;
            devMode.dmPelsHeight         = this.Bounds.Height;
            devMode.dmPelsWidth          = this.Bounds.Width;
            devMode.dmPositionX          = this.Bounds.X;
            devMode.dmPositionY          = this.Bounds.Y;
            devMode.dmSpecVersion        = this.SpecVersion;
            devMode.dmSize = (short)System.Runtime.InteropServices.Marshal.SizeOf(devMode);
            return(devMode);
        }
Example #5
0
 /// <summary>
 /// <para>The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode.</para>
 /// <para>Use this one if you are not sure</para>
 /// </summary>
 /// <param name="deviceName">
 /// <para>String that specifies the display device whose graphics mode will change. Only display device names as returned by EnumDisplayDevices are valid.</para>
 /// <para>The <paramref name="deviceName"/> parameter can be NULL. A NULL value specifies the default display device. The default device can be determined by calling EnumDisplayDevices and checking for the DISPLAY_DEVICE_PRIMARY_DEVICE flag.</para>
 /// </param>
 /// <param name="devMode"><para>A pointer to a <see cref="ScreenSettingsDevMode"/> structure that describes the new graphics mode. If <paramref name="devMode"/> is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the <paramref name="devMode"/> parameter and 0 for the <paramref name="dwFlags"/> parameter is the easiest way to return to the default mode after a dynamic mode change.</para></param>
 /// <param name="dwFlags"></param>
 /// <returns></returns>
 internal static DispChange ChangeDisplaySettingsEx(string deviceName, ref ScreenSettingsDevMode devMode, CDS dwFlags)
 {
     return((DispChange)ChangeDisplaySettingsEx(deviceName, ref devMode, IntPtr.Zero, (int)dwFlags, IntPtr.Zero));
 }
Example #6
0
 internal static extern int ChangeDisplaySettingsEx(string lpszDeviceName, ref ScreenSettingsDevMode lpDevMode, IntPtr hwnd, int dwFlags, IntPtr lParam);
Example #7
0
        /// <summary>
        /// <para>Updates the screen's settings and sets it as primary screen</para>
        /// </summary>
        /// <param name="screen"></param>
        /// <returns></returns>
        public static bool UpdateScreenAndMakePrimary(ScreenEx screen)
        {
            ScreenSettingsDevMode devMode = screen.ToDEVMODE();

            return(ChangeDisplaySettingsEx(screen.Name, ref devMode, CDS.RESET | CDS.UPDATEREGISTRY | CDS.SET_PRIMARY) >= 0);
        }
Example #8
0
 public ScreenEx(Forms.Screen screen, ScreenSettingsDevMode devMode)
 {
     this.DeviceName = screen.DeviceName;
     this.BitsPerPixel = (byte)screen.BitsPerPixel;
     this.Bounds = new Rectangle(screen.Bounds.Location, screen.Bounds.Size);
     this.Primary = screen.Primary;
     this.SpecVersion = devMode.dmSpecVersion;
     this.DriverVersion = devMode.dmDriverVersion;
     this.FixedOutput = (FixedOutput)devMode.dmDisplayFixedOutput;
     this.LogPixels = devMode.dmLogPixels;
     this.ColorDepth = (ColorDepth)devMode.dmBitsPerPel;
     this.DisplayFlags = devMode.dmDisplayFlags;
     this.Frequency = (byte)devMode.dmDisplayFrequency;
     this.Orientation = (ScreenOrientation)devMode.dmDisplayOrientation;
     this.fields = 0;
 }
Example #9
0
 /// <summary>
 /// <para>Converts this class to a <see cref="ScreenSettingsDevMode"/> struct which then may be used to update the settings</para>
 /// </summary>
 /// <returns></returns>
 public ScreenSettingsDevMode ToDEVMODE()
 {
     ScreenSettingsDevMode devMode = new ScreenSettingsDevMode(true);
     devMode.dmBitsPerPel = this.BitsPerPixel;
     devMode.dmDeviceName = this.DeviceName;
     devMode.dmDisplayFixedOutput = (int)this.FixedOutput;
     devMode.dmDisplayFlags = this.DisplayFlags;
     devMode.dmDisplayFrequency = this.Frequency;
     devMode.dmDisplayOrientation = (int)this.Orientation;
     devMode.dmDriverVersion = this.DriverVersion;
     devMode.dmFields = (int)this.fields;
     devMode.dmFormName = "";
     devMode.dmLogPixels = this.LogPixels;
     devMode.dmPelsHeight = this.Bounds.Height;
     devMode.dmPelsWidth = this.Bounds.Width;
     devMode.dmPositionX = this.Bounds.X;
     devMode.dmPositionY = this.Bounds.Y;
     devMode.dmSpecVersion = this.SpecVersion;
     devMode.dmSize = (short)System.Runtime.InteropServices.Marshal.SizeOf(devMode);
     return devMode;
 }
Example #10
0
 private static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref ScreenSettingsDevMode lpDevMode);