示例#1
0
        public static bool ChangeResolutionEx(ResolutionModeWrapper resolutionMode, string lpszDeviceName)
        {
            Devmode mode = new Devmode();

            if (GetCurrentResolutionSettings(out mode, lpszDeviceName))
            {
                mode.dmPelsWidth          = resolutionMode.DmPelsWidth;
                mode.dmPelsHeight         = resolutionMode.DmPelsHeight;
                mode.dmBitsPerPel         = resolutionMode.DmBitsPerPel;
                mode.dmDisplayFrequency   = resolutionMode.DmDisplayFrequency;
                mode.dmDisplayFixedOutput = resolutionMode.DmDisplayFixedOutput;


                DispChange returnValue = (DispChange)ChangeDisplaySettingsEx(lpszDeviceName, ref mode, IntPtr.Zero, (ChangeDisplaySettingsFlags.CdsUpdateregistry | ChangeDisplaySettingsFlags.CdsNoreset), IntPtr.Zero);
                ChangeDisplaySettingsEx(null, IntPtr.Zero, (IntPtr)null, ChangeDisplaySettingsFlags.CdsNone, (IntPtr)null);

                if (DispChange.DispChangeSuccessful == returnValue)
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Changing the resolution failed: " + Enum.GetName(typeof(DispChange), returnValue));
                }
            }
            return(false);
        }
 public ResolutionModeWrapper(Devmode mode)
 {
     this.DmPelsWidth          = mode.dmPelsWidth;
     this.DmPelsHeight         = mode.dmPelsHeight;
     this.DmBitsPerPel         = mode.dmBitsPerPel;
     this.DmDisplayFrequency   = mode.dmDisplayFrequency;
     this.DmDisplayFixedOutput = mode.dmDisplayFixedOutput;
 }
 public ResolutionModeWrapper(Devmode mode)
 {
     this.DmPelsWidth = mode.dmPelsWidth;
     this.DmPelsHeight = mode.dmPelsHeight;
     this.DmBitsPerPel = mode.dmBitsPerPel;
     this.DmDisplayFrequency = mode.dmDisplayFrequency;
     this.DmDisplayFixedOutput = mode.dmDisplayFixedOutput;
 }
示例#4
0
        public static bool GetCurrentResolutionSettings(out Devmode mode, string lpszDeviceName)
        {
            mode = new Devmode();

            mode.dmSize        = (ushort)Marshal.SizeOf(mode);
            mode.dmDriverExtra = 0;

            if (EnumDisplaySettings(lpszDeviceName, EnumCurrentSettings, ref mode) == true)
            {
                return(true);
            }

            return(false);
        }
示例#5
0
        public static List <ResolutionModeWrapper> EnumerateSupportedResolutionModes()
        {
            List <ResolutionModeWrapper> resolutionList = new List <ResolutionModeWrapper>();
            Devmode mode = new Devmode();

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

            int index = 0;

            while (EnumDisplaySettings(null, index++, ref mode) == true)
            {
                resolutionList.Add(new ResolutionModeWrapper(mode));
            }

            return(resolutionList);
        }
示例#6
0
        public static bool ChangeResolution(ResolutionModeWrapper resolutionMode)
        {
            Devmode mode = new Devmode();

            if (GetCurrentResolutionSettings(out mode, null))
            {
                mode.dmPelsWidth          = resolutionMode.DmPelsWidth;
                mode.dmPelsHeight         = resolutionMode.DmPelsHeight;
                mode.dmBitsPerPel         = resolutionMode.DmBitsPerPel;
                mode.dmDisplayFrequency   = resolutionMode.DmDisplayFrequency;
                mode.dmDisplayFixedOutput = resolutionMode.DmDisplayFixedOutput;

                DispChange returnValue = (DispChange)ChangeDisplaySettings(ref mode, 0);
                if (DispChange.DispChangeSuccessful == returnValue)
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Changing the resolution failed: " + Enum.GetName(typeof(DispChange), returnValue));
                }
            }
            return(false);
        }
示例#7
0
 private static extern DispChange ChangeDisplaySettingsEx(
     string lpszDeviceName,
     ref Devmode lpDevMode,
     IntPtr hwnd,
     ChangeDisplaySettingsFlags dwflags,
     IntPtr lParam);
示例#8
0
 private static extern int ChangeDisplaySettings(
     [In, Out]
     ref Devmode lpDevMode,
     [param: MarshalAs(UnmanagedType.U4)]
     uint dwflags);
示例#9
0
 public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref Devmode devMode);
示例#10
0
 private static extern DispChange ChangeDisplaySettingsEx(
     string lpszDeviceName,
     ref Devmode lpDevMode,
     IntPtr hwnd,
     ChangeDisplaySettingsFlags dwflags,
     IntPtr lParam);
示例#11
0
        public static bool GetCurrentResolutionSettings(out Devmode mode, string lpszDeviceName)
        {
            mode = new Devmode();
            mode.dmSize = (ushort)Marshal.SizeOf(mode);
            mode.dmDriverExtra = 0;

            if (EnumDisplaySettings(lpszDeviceName, EnumCurrentSettings, ref mode) == true)
            {
                return true;
            }

            return false;
        }
示例#12
0
        public static List<ResolutionModeWrapper> EnumerateSupportedResolutionModes()
        {
            List<ResolutionModeWrapper> resolutionList = new List<ResolutionModeWrapper>();
            Devmode mode = new Devmode();
            mode.dmSize = (ushort)Marshal.SizeOf(mode);

            int index = 0;
            while (EnumDisplaySettings(null, index++, ref mode) == true)
            {
                resolutionList.Add(new ResolutionModeWrapper(mode));
            }

            return resolutionList;
        }
示例#13
0
 public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref Devmode devMode);
示例#14
0
        public static bool ChangeResolutionEx(ResolutionModeWrapper resolutionMode, string lpszDeviceName)
        {
            Devmode mode = new Devmode();
            if (GetCurrentResolutionSettings(out mode, lpszDeviceName))
            {
                mode.dmPelsWidth = resolutionMode.DmPelsWidth;
                mode.dmPelsHeight = resolutionMode.DmPelsHeight;
                mode.dmBitsPerPel = resolutionMode.DmBitsPerPel;
                mode.dmDisplayFrequency = resolutionMode.DmDisplayFrequency;
                mode.dmDisplayFixedOutput = resolutionMode.DmDisplayFixedOutput;

                DispChange returnValue = (DispChange)ChangeDisplaySettingsEx(lpszDeviceName, ref mode, IntPtr.Zero, (ChangeDisplaySettingsFlags.CdsUpdateregistry | ChangeDisplaySettingsFlags.CdsNoreset), IntPtr.Zero);
                ChangeDisplaySettingsEx(null, IntPtr.Zero, (IntPtr)null, ChangeDisplaySettingsFlags.CdsNone, (IntPtr)null);

                if (DispChange.DispChangeSuccessful == returnValue)
                {
                    return true;
                }
                else
                {
                    MessageBox.Show("Changing the resolution failed: " + Enum.GetName(typeof(DispChange), returnValue));
                }
            }
            return false;
        }
示例#15
0
        public static bool ChangeResolution(ResolutionModeWrapper resolutionMode)
        {
            Devmode mode = new Devmode();
            if (GetCurrentResolutionSettings(out mode, null))
            {
                mode.dmPelsWidth = resolutionMode.DmPelsWidth;
                mode.dmPelsHeight = resolutionMode.DmPelsHeight;
                mode.dmBitsPerPel = resolutionMode.DmBitsPerPel;
                mode.dmDisplayFrequency = resolutionMode.DmDisplayFrequency;
                mode.dmDisplayFixedOutput = resolutionMode.DmDisplayFixedOutput;

                DispChange returnValue = (DispChange)ChangeDisplaySettings(ref mode, 0);
                if (DispChange.DispChangeSuccessful == returnValue)
                {
                    return true;
                }
                else
                {
                    MessageBox.Show("Changing the resolution failed: " + Enum.GetName(typeof(DispChange), returnValue));
                }
            }
            return false;
        }