protected override void ProcessRecord() { DISPLAY_DEVICE d = ScreenDevice.GetDesktopDeviceByName(DeviceName); if (Frequency.HasValue && Bits.HasValue) { ScreenDevice.ChangeResolution(ref d, Width, Height, Bits.Value, Frequency.Value); } else if (Bits.HasValue) { ScreenDevice.ChangeResolution(ref d, Width, Height, Bits.Value); } else { ScreenDevice.ChangeResolution(ref d, Width, Height); } }
static void RestoreCurrentResolution(string[] args) { string profileName = "Default"; bool silent = false; OptionSet p = new OptionSet() { { "p|profile=", "the {PROFILENAME} of the screen resolution. (\"Default\" is the default profile.)", v => profileName = RegistryHandler.sanitizeProfileName(v) }, { "q|quiet", "be quiet", v => silent = v != null } }; List <string> extra; try { extra = p.Parse(args); } catch (OptionException e) { if (!silent) { Console.WriteLine("ERROR: " + e.Message); } return; } foreach (RegistryProfileDeviceSettings rpds in RegistryHandler.getProfile(profileName)) { try { if (!silent) { Console.WriteLine("Restoring Screen resolution: " + rpds); } DISPLAY_DEVICE d = ScreenDevice.GetDesktopDeviceByName(rpds.DeviceName); if (rpds.Frequency > 0 && rpds.Bits > 0) { try { ScreenDevice.ChangeResolution(ref d, rpds.Width, rpds.Height, rpds.Bits, rpds.Frequency); } catch (User32Exception) { rpds.Frequency = 0; if (!silent) { Console.WriteLine("Failed to change resolution, restoring without frequency: " + rpds); } ScreenDevice.ChangeResolution(ref d, rpds.Width, rpds.Height, rpds.Bits); } } else if (rpds.Bits > 0) { ScreenDevice.ChangeResolution(ref d, rpds.Width, rpds.Height, rpds.Bits); } else { ScreenDevice.ChangeResolution(ref d, rpds.Width, rpds.Height); } } catch (Exception e) { if (!silent) { Console.WriteLine("ERROR: " + e.Message); } } } if (!silent) { Console.WriteLine("Screen resolution has been restored from profile \"" + profileName + "\"."); } }
static void SetResolution(string[] args) { string deviceName = null; int width = 0; int height = 0; short bits = 0; int frequency = 0; OptionSet p = new OptionSet() { { "d|device=", "the {NAME} of the screen device.", v => deviceName = v }, { "w|width=", "the display resolution {WIDTH} in pixels.", (int v) => width = v }, { "h|height=", "the display resolution {HEIGHT} in pixels.", (int v) => height = v }, { "b|bits=", "the display resolution {BITS}.", (short v) => bits = v }, { "f|frequency=", "the display resolution {FREQUENCY} in hertz.", (short v) => bits = v } }; List <string> extra; try { extra = p.Parse(args); } catch (OptionException e) { Console.WriteLine("ERROR: " + e.Message); return; } if (deviceName == null) { Console.WriteLine("ERROR: No device name has not been specified."); return; } if (width <= 0) { Console.WriteLine("ERROR: Invalid width specified."); return; } if (height <= 0) { Console.WriteLine("ERROR: Invalid height specified."); return; } try { DISPLAY_DEVICE d = ScreenDevice.GetDesktopDeviceByName(deviceName); if (frequency > 0 && bits > 0) { ScreenDevice.ChangeResolution(ref d, width, height, bits, frequency); } else if (bits > 0) { ScreenDevice.ChangeResolution(ref d, width, height, bits); } else { ScreenDevice.ChangeResolution(ref d, width, height); } } catch (User32Exception e) { Console.WriteLine("ERROR: " + e.Message); return; } }