public static void SetWallpaper(string filename, WallpaperStyle style) { RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true); switch (style) { case WallpaperStyle.Tile: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "1"); break; case WallpaperStyle.Center: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Stretch: key.SetValue(@"WallpaperStyle", "2"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fit: key.SetValue(@"WallpaperStyle", "6"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fill: key.SetValue(@"WallpaperStyle", "10"); key.SetValue(@"TileWallpaper", "0"); break; } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); }
/// <summary> /// Sets the current desktop wallpaper to the specified image. /// </summary> /// <param name="imagePath">The path of the image to set as the wallpaper.</param> /// <param name="style">The style.</param> public static void SetWallpaper(string imagePath, WallpaperStyle style) { // calculate registry values var wallpaperStyle = "1"; var tileWallpaper = "0"; if (style == WallpaperStyle.Stretched) { wallpaperStyle = "2"; } if (style == WallpaperStyle.Tiled) { tileWallpaper = "1"; } // set registry values var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); key.SetValue(@"WallpaperStyle", wallpaperStyle); key.SetValue(@"TileWallpaper", tileWallpaper); // set desktop backround const int SPI_SETDESKWALLPAPER = 20; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDWININICHANGE = 0x02; SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); }
/// <summary> /// Used to shorten code when changing wallpapers. /// </summary> /// <param name="wallpaperName"></param> /// <param name="wallStyle"></param> private void changeWallpaper(String wallpaperName, WallpaperStyle wallStyle) { if (!String.IsNullOrEmpty(fileNames[pCurrentImage])) { Wallpaper.SetDesktopWallpaper(fileNames[pCurrentImage], wallStyle); } }
internal void SaveWallpaperFile(Guid networkId, string wallpaperFile, WallpaperStyle style) { this.Settings[networkId + "_WallpaperFile"] = wallpaperFile; this.Settings[networkId + "_WallpaperStyle"] = style.ToString(); this.OnSettingsChanged(); }
public void SetWallpaper(string imagePath, WallpaperStyle style) { var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); if (style == WallpaperStyle.Stretched) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Centered) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Tiled) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } SystemParametersInfo(SpiSetDesktopWallpaper, 0, imagePath, SpifUpdateIniFile | SpifSendWinIniChange); System.Console.WriteLine("Set desktop wallpaper to {0}", imagePath); }
public static void SetWallpaper(string path, WallpaperStyle style) { var wallpaperStyle = style == WallpaperStyle.Fill ? "10" : style == WallpaperStyle.Fit ? "6" : style == WallpaperStyle.Span ? "22" : style == WallpaperStyle.Stretch ? "2" : style == WallpaperStyle.Tile ? "0" : style == WallpaperStyle.Center ? "0" : throw new System.ArgumentException(nameof(style)); var tileWallpaper = style == WallpaperStyle.Tile ? "1" : style == WallpaperStyle.Fill ? "0" : style == WallpaperStyle.Fit ? "0" : style == WallpaperStyle.Span ? "0" : style == WallpaperStyle.Stretch ? "0" : style == WallpaperStyle.Center ? "0" : throw new System.ArgumentException(nameof(style)); lock (locker) { using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true)) { key.SetValue(@"WallpaperStyle", wallpaperStyle); key.SetValue(@"TileWallpaper", tileWallpaper); } SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); } }
public static void SetWallpaper(string path, WallpaperStyle style) { if (!path.ToLower().EndsWith(".bmp")) { if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers")) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers"); } Image.FromFile(path).Save(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers\\" + new FileInfo(path).GetNameWithoutExtension() + ".bmp", ImageFormat.Bmp); path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers\\" + new FileInfo(path).GetNameWithoutExtension() + ".bmp"; } if (File.Exists(path)) { RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true); key.SetValue(@"WallpaperStyle", ((int)style).ToString()); key.SetValue(@"TileWallpaper", 0); User32.SystemParametersInfo(WP_UPDATEWALLPAPER, 0, path, WP_UPDATEINI | WP_SENDINICHANGE); } }
private static void SetWallpaperStyle(WallpaperStyle style) { if (style == WallpaperStyle.Fill) { SetOptions(@"WallpaperStyle", 10.ToString()); SetOptions(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Fit) { SetOptions(@"WallpaperStyle", 6.ToString()); SetOptions(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Span) // Windows 8 or newer only! { SetOptions(@"WallpaperStyle", 22.ToString()); SetOptions(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Stretch) { SetOptions(@"WallpaperStyle", 2.ToString()); SetOptions(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Tile) { SetOptions(@"WallpaperStyle", 0.ToString()); SetOptions(@"TileWallpaper", 1.ToString()); } if (style == WallpaperStyle.Center) { SetOptions(@"WallpaperStyle", 0.ToString()); SetOptions(@"TileWallpaper", 0.ToString()); } }
private void Set_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(Filepath.Text)) { MessageBox.Show("please select a file"); return; } if (Uri.IsWellFormedUriString(Filepath.Text, UriKind.RelativeOrAbsolute)) { //string folder = @"C:\Users\skoley\Pictures\Saved Pictures\"; //string filename = DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".png"; try { string savedFilePath = _picture.DownloadImage(Filepath.Text);//,folder,filename); //string savedFilePath = _picture.DownloadImage(Filepath.Text,folder,filename); if (!string.IsNullOrEmpty(savedFilePath)) { WallpaperStyle _style = (WallpaperStyle)Style.SelectedItem; Wallpaper.SilentSet(savedFilePath, _style); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { WallpaperStyle _style = (WallpaperStyle)Style.SelectedItem; Wallpaper.SilentSet(Filepath.Text, _style); } }
public void Set(Uri uri, WallpaperStyle style) { Stream s = new System.Net.WebClient().OpenRead(uri.ToString()); System.Drawing.Image img = System.Drawing.Image.FromStream(s); string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp"); img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp); RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); if (style == WallpaperStyle.Stretched) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Centered) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Tiled) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); }
private void buttonSave_Click(object sender, RoutedEventArgs e) { string wpFile = textBoxWallpaperFile.Text; string stvalue = (comboBoxWallpaperStyle.SelectedItem as ComboBoxItem).Tag.ToString(); WallpaperStyle wpStyle = (WallpaperStyle)Enum.Parse(typeof(WallpaperStyle), stvalue, true); this.changeWallpaperAction.SaveWallpaperFile(this.networkId, wpFile, wpStyle); }
private void ButtonSaveClick(object sender, RoutedEventArgs e) { GeneralFontSetting = generalFontColorChooser.SelectedFont; GeneralSignFormat = new SignFormat(generalSignFormatTextBox.Text); GeneralWallpaperStyle = (WallpaperStyle)generalWallpaperStyleComboBox.SelectedItem; DialogResult = true; }
public static void SetWallpaper(string wallpaper, WallpaperStyle wallpaperStyle = WallpaperStyle.Fill, bool tileWallpaper = false) { using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true)) { key.SetValue(@"WallpaperStyle", ((int)wallpaperStyle).ToString()); key.SetValue(@"TileWallpaper", tileWallpaper ? 1.ToString() : 0.ToString()); } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, wallpaper, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); }
/// <summary> /// set the desktop background image /// </summary> /// <param name="fileName">the path of image</param> /// <returns></returns> public static bool SetBackgroud(string fileName, WallpaperStyle wallpaperStyle) { if (SetBackgroud(fileName)) { SetWallpaperStyle(wallpaperStyle); return(true); } return(false); }
/// <summary> /// Sets the wallpaper using the specified active desktop instance to fade the image. /// </summary> /// <param name="Filename">The path to the image to set.</param> /// <param name="Style">The style for the wallpapre.</param> /// <param name="iActiveDesktop">The active desktop instance to use.</param> public static void FadeSet(string Filename, WallpaperStyle Style, IActiveDesktop iActiveDesktop) { //kill Progman, so Windows launches WorkerW instead to perform the animation var result = IntPtr.Zero; SendMessageTimeout(FindWindow("Progman", IntPtr.Zero), 0x52c, IntPtr.Zero, IntPtr.Zero, 0, 500, out result); //Use IActiveDesktop to change the wallpaper iActiveDesktop.SetWallpaperOptions(new WALLPAPEROPT { dwSize = Marshal.SizeOf(new WALLPAPEROPT()), dwStyle = (WPSTYLE)Style }, 0); iActiveDesktop.SetWallpaper(Filename, 0); iActiveDesktop.ApplyChanges(AD_APPLY.ALL | AD_APPLY.FORCE | AD_APPLY.BUFFERED_REFRESH); }
/// <summary> /// Set the desktop wallpaper. /// </summary> /// <param name="path">Path of the wallpaper</param> /// <param name="style">Wallpaper style</param> public static void SetDesktopWallpaper(string path, WallpaperStyle style) { // Set the wallpaper style and tile. // Two registry values are set in the Control Panel\Desktop key. // TileWallpaper // 0: The wallpaper picture should not be tiled // 1: The wallpaper picture should be tiled // WallpaperStyle // 0: The image is centered if TileWallpaper=0 or tiled if TileWallpaper=1 // 2: The image is stretched to fill the screen // 6: The image is resized to fit the screen while maintaining the aspect // ratio. (Windows 7 and later) // 10: The image is resized and cropped to fill the screen while // maintaining the aspect ratio. (Windows 7 and later) RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case WallpaperStyle.Tile: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "1"); break; case WallpaperStyle.Center: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Stretch: key.SetValue(@"WallpaperStyle", "2"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fit: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "6"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fill: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); // Set the desktop wallpapaer by calling the Win32 API SystemParametersInfo // with the SPI_SETDESKWALLPAPER desktop parameter. The changes should // persist, and also be immediately visible. if (!SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)) { throw new Win32Exception(); } }
public GeneralSettingsData(FileInfo selectedSound, FontInfo generalFontSettings, WallpaperStyle generalWallpaperStyle, Signature defaultSignature, TimeSpan updateFrequency, UpdateOrder wallpaperUpdateOrder, UpdateOrder phraseUpdateOrder) { SelectedSound = selectedSound; GeneralFontSettings = generalFontSettings; GeneralWallpaperStyle = generalWallpaperStyle; DefaultSignature = defaultSignature; UpdateFrequency = updateFrequency; WallpaperUpdateOrder = wallpaperUpdateOrder; PhraseUpdateOrder = phraseUpdateOrder; }
/// <summary> /// Runs the set method to put a new wallpaper on the desktop /// </summary> /// <param name="uri">The URI to the new wallpaper</param> /// <param name="style">The style of wallpaper to apply</param> public static void Set(string uri, WallpaperStyle style) { Console.WriteLine("WS: START Wallpaper set"); string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp"); using (var stream = new MemoryStream(File.ReadAllBytes(uri))) using (var image = Image.FromStream(stream, false, true)) { image.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp); } RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); if (style == WallpaperStyle.Fill) { key.SetValue(@"WallpaperStyle", 10.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Fit) { key.SetValue(@"WallpaperStyle", 6.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Span) { key.SetValue(@"WallpaperStyle", 22.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Stretch) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Tile) { key.SetValue(@"WallpaperStyle", 0.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } if (style == WallpaperStyle.Center) { key.SetValue(@"WallpaperStyle", 0.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); Console.WriteLine("WS: END Wallpaper set"); }
public static void Set(string wallpaperPath, WallpaperStyle style) { var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); key.SetValue(WALLPAPER_STYLE_KEY, style.GetWallpaperStyleKeyValue()); key.SetValue(TILE_WALLPAPER_KEY, style.GetTileWallpaperKeyValue()); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, wallpaperPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); }
public UserData() { lastWallpaperPath = new List<String>(); WallpaperDir = ""; LargeImageStyle = WallpaperStyle.Stretch; SmallImageStyle = WallpaperStyle.Center; SpecialImageStyle = WallpaperStyle.Tile; SpecialImageSize = 128; WallpaperCycleTime = 0; WallpaperSubDir = false; cycleTimeEnabled = false; }
public GeneralWallpaperSettings(FontInfo settings, SignFormat signFormat, WallpaperStyle style) { InitializeComponent(); generalWallpaperStyleComboBox.ItemsSource = Enum.GetValues(typeof(WallpaperStyle)); GeneralFontSetting = settings; GeneralSignFormat = signFormat; GeneralWallpaperStyle = style; generalFontColorChooser.SelectedFont = settings; generalSignFormatTextBox.Text = signFormat.Pattern; generalWallpaperStyleComboBox.SelectedItem = style; }
//from Microsoft example code: //http://code.msdn.microsoft.com/windowsdesktop/CSSetDesktopWallpaper-2107409c/sourcecode?fileId=21700&pathId=734742078 public static void SetWallpaperType(WallpaperStyle style) { if (style == WallpaperStyle.NotSet) { return; } // Set the wallpaper style and tile. // Two registry values are set in the Control Panel\Desktop key. // TileWallpaper // 0: The wallpaper picture should not be tiled // 1: The wallpaper picture should be tiled // WallpaperStyle // 0: The image is centered if TileWallpaper=0 or tiled if TileWallpaper=1 // 2: The image is stretched to fill the screen // 6: The image is resized to fit the screen while maintaining the aspect // ratio. (Windows 7 and later) // 10: The image is resized and cropped to fill the screen while // maintaining the aspect ratio. (Windows 7 and later) RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case WallpaperStyle.Tile: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "1"); break; case WallpaperStyle.Center: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Stretch: key.SetValue(@"WallpaperStyle", "2"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fit: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "6"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fill: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); }
public void Set(Uri uri, WallpaperStyle style) { var wallpaperPath = DownloadWallpaper(uri); SetWallpaperStyle(style); SystemParametersInfo( uAction: SPI_SETDESKWALLPAPER, uParam: 0, lpvParam: wallpaperPath, fuWinIni: SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); _wallpaperHistory.Add(uri); }
internal static void SetWallpaper(string path, WallpaperStyle style) { if (canNavigate) { if (File.Exists(path)) { try { Task.Run(() => SetDesktopWallpaper(path, style)); } #if DEBUG catch (Exception e) { Trace.WriteLine("Wallpaper exception \n" + e.Message); return; } #else catch (Exception) { return; } #endif } } else { Task.Run(() => { try { //Handle if file from web, need clipboard image solution var tempPath = Path.GetTempPath(); var randomName = Path.GetRandomFileName(); var webClient = new System.Net.WebClient(); Directory.CreateDirectory(tempPath); webClient.DownloadFile(path, tempPath + randomName); SetDesktopWallpaper(tempPath + randomName, style); File.Delete(tempPath + randomName); var timer = new Timer(2000); timer.Elapsed += (s, x) => Directory.Delete(tempPath); } #if DEBUG catch (Exception e) { Trace.WriteLine("Wallpaper download exception \n" + e.Message); return; } #else catch (Exception) { return; } #endif }); } }
public static void SetWallpaperStyle(WallpaperStyle userStyle) { RegistryKey key = Registry.CurrentUser.OpenSubKey(WALLPAPER_STYLE_PATH, true); var value = (string)key.GetValue("WallpaperStyle"); if (userStyle == WallpaperStyle.Tile || userStyle == WallpaperStyle.Center) { key.SetValue("WallpaperStyle", "0"); key.SetValue("TileWallpaper", ((int)userStyle).ToString()); return; } key.SetValue("WallpaperStyle", ((int)userStyle).ToString()); key.SetValue("TileWallpaper", "0"); }
public static string GetTileWallpaperKeyValue(this WallpaperStyle style) { if (style == WallpaperStyle.Stretched) { return("0"); } else if (style == WallpaperStyle.Centered) { return("0"); } else { return("1"); } }
private void LoadConfig() { if (_TimeSlots == null) { _TimeSlots = new SortedDictionary <TimeSpan, string>(); } else { _TimeSlots.Clear(); } Regex time = new Regex("(?<hour>\\d?\\d):(?<min>\\d\\d)"); foreach (string item in ConfigurationManager.AppSettings.Keys) { Match m = time.Match(item); string value = ConfigurationManager.AppSettings[item]; if (string.IsNullOrEmpty(value)) { continue; } if (m.Success) { int hour = Convert.ToInt32(m.Groups["hour"].Value); int min = Convert.ToInt32(m.Groups["min"].Value); TimeSpan ts = new TimeSpan(hour, min, 0); _TimeSlots.Add(ts, value); } else if (item == "transition_slices") { _TransitionSlices = Convert.ToInt32(value); } else if (item == "transition_time_ms") { _TransitionTime = Convert.ToInt32(value); } else if (item == "style") { try { _WallpaperStyle = (WallpaperStyle)Enum.Parse(typeof(WallpaperStyle), value); } catch { _WallpaperStyle = WallpaperStyle.Centered; } } } }
public static void Set(FileInfo file, WallpaperStyle style) { //Reading the desktop status, in this case, the wallpaper style RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); using (System.IO.Stream s = file.OpenRead()) { //Load generated wallpaper from the "blend" string tempPath = file.FullName; if (!file.Name.Equals("wallpaper.bmp")) { System.Drawing.Image img = System.Drawing.Image.FromStream(s); tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp"); img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp); } //Check wallpaper style if (style == WallpaperStyle.Stretched) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Centered) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Tiled) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } if (style == WallpaperStyle.Fill) { key.SetValue(@"WallpaperStyle", 10.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } //Set the wallpaper SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); } }
public static void Set(FileInfo file, WallpaperStyle style) { var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); if (key == null) { return; } using (Stream s = file.OpenRead()) { var tempPath = file.FullName; if (!file.Name.Equals("wallpaper.bmp")) { var img = Image.FromStream(s); tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp"); img.Save(tempPath, ImageFormat.Bmp); } if (style == WallpaperStyle.Stretched) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Centered) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Tiled) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } if (style == WallpaperStyle.Fill) { key.SetValue(@"WallpaperStyle", 10.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } SystemParametersInfo(SpiSetdeskwallpaper, 0, tempPath, SpifUpdateinifile | SpifSendwininichange); } }
private void setBingImage_Click(object sender, EventArgs e) { try { string savedFilePath = bingobj.GetDownloadedImagePath(); //string savedFilePath = BingBackground.GetDownloadedImagePath(); if (!string.IsNullOrEmpty(savedFilePath)) { WallpaperStyle _style = (WallpaperStyle)Style.SelectedItem; Wallpaper.SilentSet(savedFilePath, _style); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Set the background wallpaper for the current system. /// </summary> /// <param name="img">Image object to save and use as a background image.</param> /// <param name="style">The style this wallpaper should be saved with.</param> public static void setBackground(Image img, WallpaperStyle style) { // Save the image to a temporary bmp file. String tmp = Path.GetTempPath(); img.Save(Path.Combine(tmp, "bg.bmp"), ImageFormat.Bmp); // Update registry values. setRegistryValues(style); // Tell the system we have a new background. SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, Path.Combine(tmp, "bg.bmp"), SPIF_UPDATEINIFILE | SPIF_SPIF_SENDWININICHANGE ); }
public static void Set(FileInfo file, WallpaperStyle style) { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); using (System.IO.Stream s = file.OpenRead()) { string tempPath = file.FullName; if (!file.Name.Equals("wallpaper.bmp")) { System.Drawing.Image img = System.Drawing.Image.FromStream(s); tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp"); img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp); } if (style == WallpaperStyle.Stretched) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Centered) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Tiled) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } if (style == WallpaperStyle.Fill) { key.SetValue(@"WallpaperStyle", 10.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); } }
private static void SetStyle(WallpaperStyle style) { switch (style) { case WallpaperStyle.Fill: SetWallpaperConfig(new Config { Style = 10, IsTile = false }); break; case WallpaperStyle.Fit: SetWallpaperConfig(new Config { Style = 6, IsTile = false }); break; case WallpaperStyle.Stretch: SetWallpaperConfig(new Config { Style = 2, IsTile = false }); break; case WallpaperStyle.Tile: SetWallpaperConfig(new Config { Style = 0, IsTile = true }); break; case WallpaperStyle.Center: SetWallpaperConfig(new Config { Style = 0, IsTile = false }); break; case WallpaperStyle.Span: // Windows 8 or newer only SetWallpaperConfig(new Config { Style = 22, IsTile = false }); break; default: throw new ArgumentOutOfRangeException(nameof(style)); } }
//from Microsoft example code: //http://code.msdn.microsoft.com/windowsdesktop/CSSetDesktopWallpaper-2107409c/sourcecode?fileId=21700&pathId=734742078 public static void SetWallpaperType(WallpaperStyle style) { if (style == WallpaperStyle.NotSet) return; // Set the wallpaper style and tile. // Two registry values are set in the Control Panel\Desktop key. // TileWallpaper // 0: The wallpaper picture should not be tiled // 1: The wallpaper picture should be tiled // WallpaperStyle // 0: The image is centered if TileWallpaper=0 or tiled if TileWallpaper=1 // 2: The image is stretched to fill the screen // 6: The image is resized to fit the screen while maintaining the aspect // ratio. (Windows 7 and later) // 10: The image is resized and cropped to fill the screen while // maintaining the aspect ratio. (Windows 7 and later) RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case WallpaperStyle.Tile: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "1"); break; case WallpaperStyle.Center: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Stretch: key.SetValue(@"WallpaperStyle", "2"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fit: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "6"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fill: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); }
public static void Set(string path, WallpaperStyle style) { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case WallpaperStyle.Tile: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "1"); break; case WallpaperStyle.Center: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Stretch: key.SetValue(@"WallpaperStyle", "2"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fit: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "6"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fill: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); string newpath = String.Format(@"{0}\Microsoft\Windows\Themes\{1}.jpg", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetFileNameWithoutExtension(path)); if (!System.IO.File.Exists(newpath)) { System.IO.File.Copy(path, newpath); } if (!SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, newpath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)) { throw new Win32Exception(); } }
public int SetWallpaper(Uri uri, string name = "temp.png", WallpaperStyle style = WallpaperStyle.Strectched) { var tempPath = Path.Combine(Path.GetTempPath(), $"{name}"); if (!File.Exists(tempPath)) { var stream = new WebClient().OpenRead(uri.ToString()); var image = Image.FromStream(stream); image.Save(tempPath, ImageFormat.Png); } var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case WallpaperStyle.Strectched: key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); break; case WallpaperStyle.Centered: key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); break; case WallpaperStyle.Tiled: key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); break; case WallpaperStyle.Fill: key.SetValue(@"WallpaperStyle", 10.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); break; default: key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); break; } return(SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)); }
/// <summary> /// NOT thread safe! /// </summary> /// <param name="style"></param> internal static void SetWallpaper(WallpaperStyle style) { string wallpaper = FileFunctions.GetURL(UILogic.Loading.LoadWindows.GetMainWindow.TitleText.Text); if (Uri.IsWellFormedUriString(wallpaper, UriKind.Absolute)) // Check if from web { Task.Run(() => { // Create temp directory var tempPath = Path.GetTempPath(); var randomName = Path.GetRandomFileName(); // Download to it using var webClient = new System.Net.WebClient(); Directory.CreateDirectory(tempPath); webClient.DownloadFile(wallpaper, tempPath + randomName); // Use it SetDesktopWallpaper(tempPath + randomName, style); // Clean up File.Delete(tempPath + randomName); using var timer = new Timer(2000); timer.Elapsed += (s, x) => Directory.Delete(tempPath); }); return; } // TODO add Base64 support if (Pics.Count > 0) { if (FolderIndex < Pics.Count) { Task.Run(() => { SetDesktopWallpaper(Pics[FolderIndex], style); }); } } // TODO add clipboard image support }
/// <summary> /// Sets the current desktop wallpaper to the specified image. /// </summary> /// <param name="imagePath">The path of the image to set as the wallpaper.</param> /// <param name="style">The style.</param> public static void SetWallpaper(string imagePath, WallpaperStyle style) { // calculate registry values string wallpaperStyle = "1"; string tileWallpaper = "0"; if (style == WallpaperStyle.Stretched) wallpaperStyle = "2"; if (style == WallpaperStyle.Tiled) tileWallpaper = "1"; // set registry values RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); key.SetValue(@"WallpaperStyle", wallpaperStyle); key.SetValue(@"TileWallpaper", tileWallpaper); // set desktop backround const int SPI_SETDESKWALLPAPER = 20; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDWININICHANGE = 0x02; SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); }
public static void Set(string path, WallpaperStyle style = WallpaperStyle.Centered) { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); if (style == WallpaperStyle.Stretched) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Centered) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == WallpaperStyle.Tiled) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); }
public static void SetWallpaper(string path, WallpaperStyle style) { if (!path.ToLower().EndsWith(".bmp")) { if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers")) Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers"); Image.FromFile(path).Save(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers\\" + new FileInfo(path).GetNameWithoutExtension() + ".bmp", ImageFormat.Bmp); path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers\\" + new FileInfo(path).GetNameWithoutExtension() + ".bmp"; } if (File.Exists(path)) { RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true); key.SetValue(@"WallpaperStyle", ((int)style).ToString()); key.SetValue(@"TileWallpaper", 0); User32.SystemParametersInfo(WP_UPDATEWALLPAPER, 0, path, WP_UPDATEINI | WP_SENDINICHANGE); } }
public virtual void ChangeWallpaper(string file, WallpaperStyle s) { if (File.Exists(file) == false) { return; } RegistryKey rkWallPaper = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true); if (rkWallPaper != null) { switch (s) { case WallpaperStyle.Stretched: rkWallPaper.SetValue(@"WallpaperStyle", 2.ToString()); rkWallPaper.SetValue(@"TileWallpaper", 0.ToString()); break; case WallpaperStyle.Centered: rkWallPaper.SetValue(@"WallpaperStyle", 1.ToString()); rkWallPaper.SetValue(@"TileWallpaper", 0.ToString()); break; case WallpaperStyle.Tiled: rkWallPaper.SetValue(@"WallpaperStyle", 1.ToString()); rkWallPaper.SetValue(@"TileWallpaper", 1.ToString()); break; default: //unreachable break; } //Set wallpaper SystemParametersInfo(20, 0, file, 0x01 | 0x02); rkWallPaper.Close(); } }
public static void SetWallpaper(Image img, WallpaperStyle style) { if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers")) Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers"); String path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Wallpapers\\" + Path.GetRandomFileName() + ".bmp"; img.Save(path); if (File.Exists(path)) { RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true); key.SetValue(@"WallpaperStyle", ((int)style).ToString()); key.SetValue(@"TileWallpaper", 0); User32.SystemParametersInfo(WP_UPDATEWALLPAPER, 0, path, WP_UPDATEINI | WP_SENDINICHANGE); } }
/// <summary> /// Sets the wallpaper using active desktop to fade the image. /// </summary> /// <param name="Filename">The path to the image to set.</param> /// <param name="Style">The style for the wallpaper.</param> public static void FadeSet(string Filename, WallpaperStyle Style) { //Use IActiveDesktop to change the wallpaper var iad = GetActiveDesktop(); FadeSet(Filename, Style, iad); }
/// <summary> /// Set the desktop wallpaper. /// </summary> /// <param name="path">Path of the wallpaper</param> /// <param name="style">Wallpaper style</param> public static void SetDesktopWallpaper(string path, WallpaperStyle style) { // Set the wallpaper style and tile. // Two registry values are set in the Control Panel\Desktop key. // TileWallpaper // 0: The wallpaper picture should not be tiled // 1: The wallpaper picture should be tiled // WallpaperStyle // 0: The image is centered if TileWallpaper=0 or tiled if TileWallpaper=1 // 2: The image is stretched to fill the screen // 6: The image is resized to fit the screen while maintaining the aspect // ratio. (Windows 7 and later) // 10: The image is resized and cropped to fill the screen while // maintaining the aspect ratio. (Windows 7 and later) RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { case WallpaperStyle.Tile: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "1"); break; case WallpaperStyle.Center: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Stretch: key.SetValue(@"WallpaperStyle", "2"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fit: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "6"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Fill: // (Windows 7 and later) key.SetValue(@"WallpaperStyle", "10"); key.SetValue(@"TileWallpaper", "0"); break; } key.Close(); // If the specified image file is neither .bmp nor .jpg, - or - // if the image is a .jpg file but the operating system is Windows Server // 2003 or Windows XP/2000 that does not support .jpg as the desktop // wallpaper, convert the image file to .bmp and save it to the // %appdata%\Microsoft\Windows\Themes folder. string ext = Path.GetExtension(path); if ((!ext.Equals(".bmp", StringComparison.OrdinalIgnoreCase) && !ext.Equals(".jpg", StringComparison.OrdinalIgnoreCase)) || (ext.Equals(".jpg", StringComparison.OrdinalIgnoreCase) && !SupportJpgAsWallpaper)) { using (Image image = Image.FromFile(path)) { path = String.Format(@"{0}\Microsoft\Windows\Themes\{1}.bmp", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetFileNameWithoutExtension(path)); image.Save(path, ImageFormat.Bmp); } } // Set the desktop wallpaper by calling the Win32 API SystemParametersInfo // with the SPI_SETDESKWALLPAPER desktop parameter. The changes should // persist, and also be immediately visible. if (!SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)) { throw new Win32Exception(); } }
public static void SetDesktopBackground(Bitmap img, WallpaperStyle style) { // Clear the current background (releases lock on current bitmap) SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); // Convert to BMP and save) img.Save(LocalWallpaperPath, System.Drawing.Imaging.ImageFormat.Bmp); //Write style info to registry RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true); switch (style) { case WallpaperStyle.Center: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "0"); break; case WallpaperStyle.Tile: key.SetValue(@"WallpaperStyle", "1"); key.SetValue(@"TileWallpaper", "1"); break; case WallpaperStyle.Stretch: key.SetValue(@"WallpaperStyle", "2"); key.SetValue(@"TileWallpaper", "0"); break; } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, LocalWallpaperPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); }
//Loading settings from the WallpaperChange.exe.xml private void LoadConfig() { if (_TimeSlots == null) _TimeSlots = new SortedDictionary<TimeSpan, string>(); else _TimeSlots.Clear(); Regex time = new Regex("(?<hour>\\d?\\d):(?<min>\\d\\d)"); foreach (string item in ConfigurationManager.AppSettings.Keys) { Match m = time.Match(item); string value = ConfigurationManager.AppSettings[item]; if (string.IsNullOrEmpty(value)) continue; if (m.Success) { int hour = Convert.ToInt32(m.Groups["hour"].Value); int min = Convert.ToInt32(m.Groups["min"].Value); TimeSpan ts = new TimeSpan(hour, min, 0); _TimeSlots.Add(ts, value); } //Worth nothing, both "transition_slices" and "transition_time_ms" have "failsafes" //to avoid a user setting them as "0" on the XML and then crashing the application. else if (item == "transition_slices") { _TransitionSlices = Convert.ToInt32(value); if (_TransitionSlices == 0) { _TransitionSlices = 5; } } else if (item == "transition_time_ms") { _TransitionTime = Convert.ToInt32(value); if (_TransitionTime == 0) { _TransitionTime = 5000; } } else if (item == "style") { try { _WallpaperStyle = (WallpaperStyle)Enum.Parse(typeof(WallpaperStyle), value); } catch { _WallpaperStyle = WallpaperStyle.Centered; } } } }