/// <summary> /// Sets a given image file into desired layout and then updates the system /// with the systemParametersInfo call /// </summary> /// <param name="directroy">Given directory of file on hard disk</param> /// <param name="style">Layout of the image</param> public static void setImage(string directroy, PicturePosition style) { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case PicturePosition.Tile: key.SetValue(@"PicturePosition", "0"); key.SetValue(@"TileWallpaper", "1"); break; case PicturePosition.Center: key.SetValue(@"PicturePosition", "0"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Stretch: key.SetValue(@"PicturePosition", "2"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Fit: key.SetValue(@"PicturePosition", "6"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Fill: key.SetValue(@"PicturePosition", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); SystemParametersInfo(SET_DESKTOP_BACKGROUND, 0, directroy, UPDATE_INI_FILE | SEND_WINDOWS_INI_CHANGE); }
/// <summary> /// Changes the current desktop background. /// </summary> /// <param name="filepath">The path to the image to use.</param> /// <param name="sizing">The sizing to use.</param> /// <param name="copy">Whether to create and use a copy of the image.</param> public static void SetWallpaper(string filepath, PicturePosition sizing, bool copy) { if (!File.Exists(filepath)) { throw new FileNotFoundException("Invalid filepath specified for wallpaper"); } // Get full path to file filepath = Path.GetFullPath(filepath); if (copy) { string tmpFile = Path.GetTempFileName(); tmpFile = tmpFile.Substring(0, tmpFile.LastIndexOf(".")) + Path.GetExtension(filepath); File.Copy(filepath, (filepath = tmpFile), true); } using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true)) { key.SetValue("WallpaperStyle", ((int)sizing).ToString()); key.SetValue("TileWallpaper", sizing == PicturePosition.Tile ? "1" : "0"); } int res = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filepath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); if (res < 0) { throw new ExternalException("Error setting desktop background", res); } }
private static PicturePosition GetPosition() { if (string.IsNullOrEmpty(settings.Values.PicturePosition)) { return(PicturePosition.Fit); } PicturePosition position = PicturePosition.Fit; switch (settings.Values.PicturePosition) { case "Tile": position = PicturePosition.Tile; break; case "Center": position = PicturePosition.Center; break; case "Stretch": position = PicturePosition.Stretch; break; case "Fit": position = PicturePosition.Fit; break; case "Fill": position = PicturePosition.Fill; break; } Console.WriteLine("Using {0} as position", position.ToString()); return(position); }
private static PicturePosition GetPosition() { PicturePosition position = PicturePosition.Fit; switch (Properties.Settings.Default.Position) { case "Tile": position = PicturePosition.Tile; break; case "Center": position = PicturePosition.Center; break; case "Stretch": position = PicturePosition.Stretch; break; case "Fit": position = PicturePosition.Fit; break; case "Fill": position = PicturePosition.Fill; break; } return(position); }
private static void SetBackground(PicturePosition style) { Console.WriteLine("Setting background..."); Log.Information("Setting background..."); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(Path.Combine("Control Panel", "Desktop"), true)) { switch (style) { case PicturePosition.Tile: key.SetValue("PicturePosition", "0"); key.SetValue("TileWallpaper", "1"); break; case PicturePosition.Center: key.SetValue("PicturePosition", "0"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Stretch: key.SetValue("PicturePosition", "2"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fit: key.SetValue("PicturePosition", "6"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fill: key.SetValue("PicturePosition", "10"); key.SetValue("TileWallpaper", "0"); break; } } const int SetDesktopBackground = 20; const int UpdateIniFile = 1; const int SendWindowsIniChange = 2; NativeMethods.SystemParametersInfo(SetDesktopBackground, 0, GetBackgroundImagePath(), UpdateIniFile | SendWindowsIniChange); } Console.WriteLine("Finish Windows part."); Log.Debug("Finish Windows part."); if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Console.WriteLine("Platform debugging..."); Log.Debug("Platform debugging..."); var output = Bash($"osascript -e 'tell application \"Finder\" to set desktop picture to POSIX file \"{GetBackgroundImagePath()}\"'"); Console.WriteLine($"Platform debugging end. Output: {output}"); Log.Debug($"Platform debugging end. Output: {output}"); } }
public void Set(string URL, PicturePosition style) { HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL); HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream stream = httpWebReponse.GetResponseStream(); Image backgroundImage = Image.FromStream(stream); int backgroundNumber = 0; string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "/Backgrounds/"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string fullBackgroundFilePath = Path.Combine(directory, String.Format("background{0}.bmp", backgroundNumber)); while (System.IO.File.Exists(fullBackgroundFilePath)) { backgroundNumber++; fullBackgroundFilePath = Path.Combine(directory, String.Format("background{0}.bmp", backgroundNumber)); } backgroundImage.Save(fullBackgroundFilePath, System.Drawing.Imaging.ImageFormat.Bmp); RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case PicturePosition.Tile: key.SetValue(@"PicturePosition", "0"); key.SetValue(@"TileWallpaper", "1"); break; case PicturePosition.Center: key.SetValue(@"PicturePosition", "0"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Stretch: key.SetValue(@"PicturePosition", "2"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Fit: key.SetValue(@"PicturePosition", "6"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Fill: key.SetValue(@"PicturePosition", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); SystemParametersInfo(SET_DESKTOP_BACKGROUND, 0, fullBackgroundFilePath, UPDATE_INI_FILE | SEND_WINDOWS_INI_CHANGE); }
private static Boolean SetBackground(string ImgFullName, PicturePosition style) { Console.WriteLine("Setting background..."); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(Path.Combine("Control Panel", "Desktop"), true)) { switch (style) { case PicturePosition.Tile: key.SetValue("WallpaperStyle", "0"); key.SetValue("TileWallpaper", "1"); break; case PicturePosition.Center: key.SetValue("WallpaperStyle", "0"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Stretch: key.SetValue("WallpaperStyle", "2"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fit: key.SetValue("WallpaperStyle", "6"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fill: key.SetValue("WallpaperStyle", "10"); key.SetValue("TileWallpaper", "0"); break; } } const int SetDesktopBackground = 20; const int UpdateIniFile = 1; const int SendWindowsIniChange = 2; int NumResult = NativeMethods.SystemParametersInfo(SetDesktopBackground, 0, ImgFullName, UpdateIniFile | SendWindowsIniChange); if (NumResult == 1) { Console.WriteLine("Background updated succesfully!"); return(true); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Background update failed..."); Console.ForegroundColor = ConsoleColor.Gray; return(false); } }
private static void SetBackground(PicturePosition style) { logger.Information("Setting background..."); using (var key = Registry.CurrentUser.OpenSubKey(Path.Combine("Control Panel", "Desktop"), true)) { if (key == null) { throw new NullReferenceException("Could not open registry key for writing."); } switch (style) { case PicturePosition.Tile: key.SetValue("PicturePosition", "0"); key.SetValue("TileWallpaper", "1"); break; case PicturePosition.Center: key.SetValue("PicturePosition", "0"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Stretch: key.SetValue("PicturePosition", "2"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fit: key.SetValue("PicturePosition", "6"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fill: key.SetValue("PicturePosition", "10"); key.SetValue("TileWallpaper", "0"); break; default: throw new ArgumentOutOfRangeException(nameof(style), style, null); } } NativeMethods.SystemParametersInfo(SET_DESKTOP_BACKGROUND, 0, GetBackgroundImagePath(), UPDATE_INI_FILE | SEND_WINDOWS_INI_CHANGE); }
public void SetBackground(ImageExt background, PicturePosition style) { Console.WriteLine("Setting Wallpaper"); RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); //PrintUserKeys(key); switch (style) { case PicturePosition.Tile: key.SetValue(@"PicturePosition", "0"); key.SetValue(@"TileWallpaper", "1"); break; case PicturePosition.Center: key.SetValue(@"PicturePosition", "0"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Stretch: key.SetValue(@"PicturePosition", "2"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Fit: key.SetValue(@"PicturePosition", "6"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Fill: key.SetValue(@"PicturePosition", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); const int SET_DESKTOP_BACKGROUND = 20; const int UPDATE_INI_FILE = 1; const int SEND_WINDOWS_INI_CHANGE = 2; NativeMethods.SystemParametersInfo(SET_DESKTOP_BACKGROUND, 0, getBackgroundPath(background), UPDATE_INI_FILE | SEND_WINDOWS_INI_CHANGE); Console.WriteLine("Wallpaper set to Image at path "); }
public static void setBackground(PicturePosition style, String filePath) { //Console.WriteLine("Setting background..."); RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case PicturePosition.Tile: key.SetValue(@"PicturePosition", "0"); key.SetValue(@"TileWallpaper", "1"); break; case PicturePosition.Center: key.SetValue(@"PicturePosition", "0"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Stretch: key.SetValue(@"PicturePosition", "2"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Fit: key.SetValue(@"PicturePosition", "6"); key.SetValue(@"TileWallpaper", "0"); break; case PicturePosition.Fill: key.SetValue(@"PicturePosition", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); const int SET_DESKTOP_BACKGROUND = 20; const int UPDATE_INI_FILE = 1; const int SEND_WINDOWS_INI_CHANGE = 2; NativeMethods.SystemParametersInfo(SET_DESKTOP_BACKGROUND, 0, filePath, UPDATE_INI_FILE | SEND_WINDOWS_INI_CHANGE); Console.WriteLine("Wallpaper set and done!"); }
private static void SetBackground(string image, PicturePosition style) { Console.WriteLine("Setting background..."); using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(Path.Combine("Control Panel", "Desktop"), true)) { switch (style) { case PicturePosition.Tile: registryKey.SetValue("PicturePosition", "0"); registryKey.SetValue("TileWallpaper", "1"); break; case PicturePosition.Center: registryKey.SetValue("PicturePosition", "0"); registryKey.SetValue("TileWallpaper", "0"); break; case PicturePosition.Stretch: registryKey.SetValue("PicturePosition", "2"); registryKey.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fit: registryKey.SetValue("PicturePosition", "6"); registryKey.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fill: registryKey.SetValue("PicturePosition", "10"); registryKey.SetValue("TileWallpaper", "0"); break; } } const int SetDesktopBackground = 20; const int UpdateIniFile = 1; const int SendWindowsIniChange = 2; NativeMethods.SystemParametersInfo(SetDesktopBackground, 0, image, UpdateIniFile | SendWindowsIniChange); }
private static PicturePosition GetPosition() { PicturePosition position = PicturePosition.Fill; //switch (Properties.Settings.Default.Position) //{ // case "Tile": // position = PicturePosition.Tile; // break; // case "Center": // position = PicturePosition.Center; // break; // case "Stretch": // position = PicturePosition.Stretch; // break; // case "Fit": // position = PicturePosition.Fit; // break; // case "Fill": // position = PicturePosition.Fill; // break; //} return(position); }
/// <summary> /// Changes the current desktop background. /// </summary> /// <param name="filepath">The path to the image to use.</param> /// <param name="sizing">The sizing to use.</param> /// <param name="copy">Whether to create and use a copy of the image.</param> public static void SetWallpaper(string filepath, PicturePosition sizing, bool copy) { if (!File.Exists(filepath)) throw new FileNotFoundException("Invalid filepath specified for wallpaper"); // Get full path to file filepath = Path.GetFullPath(filepath); if (copy) { string tmpFile = Path.GetTempFileName(); tmpFile = tmpFile.Substring(0, tmpFile.LastIndexOf(".")) + Path.GetExtension(filepath); File.Copy(filepath, (filepath = tmpFile), true); } using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true)) { key.SetValue("WallpaperStyle", ((int)sizing).ToString()); key.SetValue("TileWallpaper", sizing == PicturePosition.Tile ? "1" : "0"); } int res = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filepath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); if (res < 0) throw new ExternalException("Error setting desktop background", res); }
/// <summary> /// Changes the current desktop background to the given image. /// </summary> /// <param name="filepath">The path to the image to use.</param> /// <param name="sizing">The sizing to use.</param> public static void SetWallpaper(string filepath, PicturePosition sizing) { WallpaperInterop.SetWallpaper(filepath, sizing, false); }
/// <summary> /// Begins a new slideshow, cancelling any active ones and setting the initial /// background. /// </summary> /// <param name="path">The path to the background directory.</param> /// <param name="position">The position with which the background will be displayed.</param> /// <param name="interval">The interval before which the next background will be set.</param> /// <param name="index">The file index within the directory at which to begin.</param> public static void BeginSlideshow(string path, PicturePosition position, int interval, int index) { if (interval < 0) throw new ArgumentOutOfRangeException("showInterval"); if (index < 0) throw new ArgumentOutOfRangeException("showIndex"); // Get the absolute path to the directory path = Path.GetFullPath(path); // Get the current images in the given directory string[] images = GetBackgroundsInFolder(path); // Wrap index if (index >= images.Length) index = 0; // Clamp interval interval = Math.Min(interval, 44640); // Save registry values using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true)) { key.SetValue("WWU CurrentIndex", index); key.SetValue("WWU CurrentInterval", interval); key.SetValue("WWU CurrentDir", path); } // Remove any current slideshows CancelSlideshow(); // Schedule slideshow using (TaskService service = new TaskService()) { // Create new task TaskDefinition task = service.NewTask(); // Create time trigger var trigger = new TimeTrigger(); trigger.SetRepetition(TimeSpan.FromMinutes(interval), TimeSpan.Zero); task.Triggers.Add(trigger); task.Settings.StartWhenAvailable = true; task.Settings.WakeToRun = false; // Add re-execution to set next background task.Actions.Add(new ExecAction(GetWallpaperwExe() + " /next")); // Register task service.RootFolder.RegisterTaskDefinition("wwu_slideshow", task); } // Now actually set the first wallpaper // Set blank if no images in folder if (images.Length == 0) { WallpaperInterop.SetWallpaper("", PicturePosition.Center, false); } // Otherwise set background to the next image else { WallpaperInterop.SetWallpaper(images[index], position, false); } }
/// <summary> /// Sets the Bing Image of the Day as the desktop background /// </summary> /// <param name="style">The PicturePosition to use</param> private static void SetBackground(PicturePosition style) { Console.WriteLine("Setting background..."); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(Path.Combine("Control Panel", "Desktop"), true)) { switch (style) { case PicturePosition.Tile: key.SetValue("PicturePosition", "0"); key.SetValue("TileWallpaper", "1"); break; case PicturePosition.Center: key.SetValue("PicturePosition", "0"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Stretch: key.SetValue("PicturePosition", "2"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fit: key.SetValue("PicturePosition", "6"); key.SetValue("TileWallpaper", "0"); break; case PicturePosition.Fill: key.SetValue("PicturePosition", "10"); key.SetValue("TileWallpaper", "0"); break; } } const int SetDesktopBackground = 20; const int UpdateIniFile = 1; const int SendWindowsIniChange = 2; NativeMethods.SystemParametersInfo(SetDesktopBackground, 0, GetBackgroundImagePath(), UpdateIniFile | SendWindowsIniChange); }
/// <summary> /// Creates a new ProgramOptions object, processing the given /// command line arguments. /// </summary> public ProgramOptions(string[] args) { // Set defaults this.ShowInterval = 60; this.Position = PicturePosition.Fill; // Process options for (int i = 1; i < args.Length; i++) { if (args[1] == "/endshow") { this.EndShow = true; } else if (args[i] == "/L") // Don't copy { this.Copy = false; } else if (args[i] == "/D") // Directory { this.Directory = true; } else if (args[i] == "/S") // Slideshow { this.Slideshow = true; } else if (args[i] == "/I") // Interval { i++; if (args.Length == i) { Program.errorOut("Expected parameter for option '/I'"); } else { uint interval; if (!UInt32.TryParse(args[i], out interval)) { Program.errorOut("Invalid parameter for option '/I'"); } this.ShowInterval = (int)Math.Min(interval, int.MaxValue); } this.Slideshow = true; } else if (args[i] == "/i") // Index { i++; if (args.Length == i) { Program.errorOut("Expected parameter for option '/i'"); } else { uint index; if (!UInt32.TryParse(args[i], out index)) { Program.errorOut("Invalid parameter for option '/i'"); } this.ShowIndex = (int)Math.Min(index, int.MaxValue); } this.Slideshow = true; } else if (args[i] == "/P") // Set PicturePosition { i++; if (args.Length == i) { Program.errorOut("Expected parameter for option '/P'"); } else { PicturePosition pos; if (!Enum.TryParse(args[i], out pos)) { Program.errorOut("Invalid parameter for option '/P'"); } this.Position = pos; } } else { Program.errorOut("Invalid parameter: " + args[i]); } } }
/// <summary> /// Begins a new slideshow, cancelling any active ones and setting the initial /// background. /// </summary> /// <param name="path">The path to the background directory.</param> /// <param name="position">The position with which the background will be displayed.</param> /// <param name="interval">The interval before which the next background will be set.</param> /// <param name="index">The file index within the directory at which to begin.</param> public static void BeginSlideshow(string path, PicturePosition position, int interval, int index) { if (interval < 0) { throw new ArgumentOutOfRangeException("showInterval"); } if (index < 0) { throw new ArgumentOutOfRangeException("showIndex"); } // Get the absolute path to the directory path = Path.GetFullPath(path); // Get the current images in the given directory string[] images = GetBackgroundsInFolder(path); // Wrap index if (index >= images.Length) { index = 0; } // Clamp interval interval = Math.Min(interval, 44640); // Save registry values using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true)) { key.SetValue("WWU CurrentIndex", index); key.SetValue("WWU CurrentInterval", interval); key.SetValue("WWU CurrentDir", path); } // Remove any current slideshows CancelSlideshow(); // Schedule slideshow using (TaskService service = new TaskService()) { // Create new task TaskDefinition task = service.NewTask(); // Create time trigger var trigger = new TimeTrigger(); trigger.SetRepetition(TimeSpan.FromMinutes(interval), TimeSpan.Zero); task.Triggers.Add(trigger); task.Settings.StartWhenAvailable = true; task.Settings.WakeToRun = false; // Add re-execution to set next background task.Actions.Add(new ExecAction(GetWallpaperwExe() + " /next")); // Register task service.RootFolder.RegisterTaskDefinition("wwu_slideshow", task); } // Now actually set the first wallpaper // Set blank if no images in folder if (images.Length == 0) { WallpaperInterop.SetWallpaper("", PicturePosition.Center, false); } // Otherwise set background to the next image else { WallpaperInterop.SetWallpaper(images[index], position, false); } }