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 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); }
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); }
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); }
private static extern DispChange ChangeDisplaySettingsEx( string lpszDeviceName, ref Devmode lpDevMode, IntPtr hwnd, ChangeDisplaySettingsFlags dwflags, IntPtr lParam);
private static extern int ChangeDisplaySettings( [In, Out] ref Devmode lpDevMode, [param: MarshalAs(UnmanagedType.U4)] uint dwflags);
public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref Devmode devMode);
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; }
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; }
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 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; }