Exemplo n.º 1
0
 private static bool TryGetCurrentMode(string deviceName, out DEVMODE devMode)
 {
     devMode = new DEVMODE {
         dmSize = (ushort)Marshal.SizeOf(typeof(DEVMODE))
     };
     return(User32Ex.EnumDisplaySettings(deviceName, User32Ex.ENUM_CURRENT_SETTINGS, ref devMode));
 }
Exemplo n.º 2
0
        public static bool ChangeResolution(string deviceName, Resolution newResolution)
        {
            Guard.Against.NullOrEmpty(deviceName, nameof(deviceName));

            if (!TryGetCurrentMode(deviceName, out var devMode))
            {
                return(false);
            }

            devMode.dmPelsWidth  = newResolution.Width;
            devMode.dmPelsHeight = newResolution.Height;
            var result = User32Ex.ChangeDisplaySettingsEx(deviceName, ref devMode, IntPtr.Zero, 0, IntPtr.Zero);

            return(result == User32Ex.DISP_CHANGE_SUCCESSFUL);
        }