示例#1
0
 static void ChangeWallPaper()
 {
     try
     {
         var pathElement = _driver.FindElementById("picture-background");
         var url         = pathElement.GetAttribute("src");
         if (_currentImageUrl != url)
         {
             _currentImageUrl = url;
             using (WebClient client = new WebClient())
             {
                 IActiveDesktop iad = shlobj.GetActiveDesktop();
                 client.DownloadFile(new Uri(url), "wallpaper");
                 iad.SetWallpaper(Path.Combine(Environment.CurrentDirectory, "wallpaper"), 0);
                 WALLPAPEROPT wopt = new WALLPAPEROPT();
                 iad.GetWallpaperOptions(ref wopt, 0);
                 wopt.dwStyle = WallPaperStyle.WPSTYLE_STRETCH;
                 wopt.dwSize  = WALLPAPEROPT.SizeOf;
                 iad.SetWallpaperOptions(ref wopt, 0);
                 iad.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH);
             }
         }
     }
     catch
     {
         //driver died most likely, it will get restarted
     }
 }
示例#2
0
 /// <summary>
 /// performs events necessary to change wallpaper
 /// </summary>
 /// <param name="path">path of new wallpaper</param>
 /// <param name="tile">tile switch</param>
 /// <param name="style">style switch, 2 = centered</param>
 private void setwallpaper(string path, int tile, int style)
 {
     if(fade7.Checked)
     {
         IActiveDesktop ad = (IActiveDesktop)new ActiveDesktop();
         WALLPAPEROPT opts = new WALLPAPEROPT();
         opts.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(opts);
         ad.GetWallpaperOptions(ref opts, 0);
         opts.dwStyle = WPSTYLE.TILE;
         ad.SetWallpaperOptions(ref opts, 0);
         ad.SetWallpaper(path, 0);
         ad.ApplyChanges(AD_APPLY.ALL);
     }
     else
     {
         RegistryKey ourkey = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
         ourkey.SetValue("Wallpaper", path);
         ourkey.SetValue("TileWallpaper", tile.ToString());
         ourkey.SetValue("WallpaperStyle", style.ToString());
         ourkey.Close();
         SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_SENDWININICHANGE);
     }
 }