public void nextBG() { if (currentBG <= imageList.Length) { string strFile = imageList[currentBG]; int dwReserved = 0; ad.SetWallpaper(strFile, dwReserved); try { ad.ApplyChanges(AD_APPLY.ALL | AD_APPLY.FORCE | AD_APPLY.BUFFERED_REFRESH); currentBG++; } catch (Exception e) { Console.Out.WriteLine(e.ToString()); } } else { currentBG = 0; imageList.Reverse(); } }
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 } }
public static void SetWallpaper(string imagePath) { IActiveDesktop iad = GetActiveDesktop(); iad.SetWallpaper(imagePath, 0); iad.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH); }
public static void SetWallpaper(string imagePath) { EnableTransitions(); if (Environment.OSVersion.Version.Major >= 8) { // TODO Support multiple monitors DesktopWallpaperFactory.Create().SetWallpaper(null, imagePath); SyncVirtualDesktops(imagePath); } else { ThreadStart threadStarter = () => { IActiveDesktop _activeDesktop = ActiveDesktopWrapper.GetActiveDesktop(); _activeDesktop.SetWallpaper(imagePath, 0); _activeDesktop.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE); Marshal.ReleaseComObject(_activeDesktop); SyncVirtualDesktops(imagePath); }; Thread thread = new Thread(threadStarter); thread.SetApartmentState(ApartmentState.STA); // Set the thread to STA (required!) thread.Start(); thread.Join(2000); } }
private void setImage(string path) { if (!File.Exists(path)) { return; } iad.SetWallpaper(path, 0); iad.ApplyChanges(AD_Apply.SAVE | AD_Apply.HTMLGEN | AD_Apply.REFRESH | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH); }
/// <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); }
public static void Main(string[] args) { Options options = new Options(); bool valid = CommandLine.Parser.Default.ParseArgumentsStrict(args, options); if (valid) { IActiveDesktop activeDesktop = ActiveDesktop.Create(); string filePath = options.File; string style = options.Style; WallPaperStyle wpStyle = WallPaperStyle.WPSTYLE_CROPTOFIT; if (style.Equals("center")) { wpStyle = WallPaperStyle.WPSTYLE_CENTER; } else if (style.Equals("tile")) { wpStyle = WallPaperStyle.WPSTYLE_TILE; } else if (style.Equals("stretch")) { wpStyle = WallPaperStyle.WPSTYLE_STRETCH; } else if (style.Equals("keep-aspect")) { wpStyle = WallPaperStyle.WPSTYLE_KEEPASPECT; } else if (style.Equals("crop-to-fit")) { wpStyle = WallPaperStyle.WPSTYLE_CROPTOFIT; } else if (style.Equals("span")) { wpStyle = WallPaperStyle.WPSTYLE_SPAN; } WALLPAPEROPT wallpaperOpt = new WALLPAPEROPT(); wallpaperOpt.dwStyle = wpStyle; wallpaperOpt.SizeOf = Marshal.SizeOf(typeof(WALLPAPEROPT)); IntPtr progmanWindow = User32.FindWindow("Progman", null); User32.SendMessage(progmanWindow, 0x52c, IntPtr.Zero, IntPtr.Zero); activeDesktop.SetWallpaper(filePath, 0); activeDesktop.SetWallpaperOptions(ref wallpaperOpt, 0); activeDesktop.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH); } else { Console.WriteLine("Invalid Command Line Arguments"); } }
private static void _downloader_WallpaperChanged(object sender, WallpaperChangedEventArgs e) { //NativeMethods.SystemParametersInfo(NativeMethods.SPI_SETDESKWALLPAPER, 0, Path.GetFullPath(filename), // NativeMethods.SPIF_UPDATEINIFILE | NativeMethods.SPIF_SENDCHANGE); _mainForm.Invoke((MethodInvoker) delegate { IActiveDesktop iad = shlobj.GetActiveDesktop(); iad.SetWallpaper(Path.GetFullPath(e.WallpaperFilePath), 0); iad.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH); Marshal.ReleaseComObject(iad); }); }
private void SetWallpaperWithFade(string wallpaperFile) { var hWnd = NativeMethods.FindWindow("Progman", IntPtr.Zero); NativeMethods.SendMessageTimeout(hWnd, 0x52c, IntPtr.Zero, IntPtr.Zero, 0, 500, out IntPtr _); _activeDesktop.SetWallpaper(wallpaperFile, 0); const AD_Apply flags = AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH; _activeDesktop.ApplyChanges(flags); }
public void CycleWallpaper(bool backwards = false) { if (SlideShowFiles.Count < 2) // If there are no more images in the queue { cycleTimer.Enabled = false; SlideShowFiles.Clear(); SlideShowHistory.Clear(); startButton.Enabled = false; stopButton.Enabled = false; MessageBox.Show("The slideshow has completed - there are no images left in the queue. Please scan again to fill the queue.", "Slideshow finished.", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!backwards) { int offset = SlideShowFiles.Count - 1; IActiveDesktop iad = shlobj.GetActiveDesktop(); iad.SetWallpaper(SlideShowFiles[offset], 0); iad.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH); pictureBox1.ImageLocation = SlideShowFiles[offset]; SlideShowHistory.Add(SlideShowFiles[offset]); SlideShowFiles.RemoveAt(offset); return; } else { if (SlideShowHistory.Count < 2) { MessageBox.Show("There are no images to skip backwards to.", "Cannot skip backward.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int offset = SlideShowHistory.Count - 2; IActiveDesktop iad = shlobj.GetActiveDesktop(); iad.SetWallpaper(SlideShowHistory[offset], 0); iad.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH); pictureBox1.ImageLocation = SlideShowHistory[offset]; string item = SlideShowHistory[offset]; SlideShowHistory.Add(item); SlideShowHistory.RemoveAt(offset); return; } }
public static void SetWallpaper(string imagePath) { ThreadStart threadStarter = () => { IActiveDesktop _activeDesktop = ActiveDesktopWrapper.GetActiveDesktop(); _activeDesktop.SetWallpaper(imagePath, 0); _activeDesktop.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE); Marshal.ReleaseComObject(_activeDesktop); }; Thread thread = new Thread(threadStarter); thread.SetApartmentState(ApartmentState.STA); // Set the thread to STA (required!) thread.Start(); thread.Join(2000); }
private static void SetWallpaper(String file) { WALLPAPEROPT wallpaperOpt = new WALLPAPEROPT(); wallpaperOpt.dwStyle = WallPaperStyle.WPSTYLE_CROPTOFIT; wallpaperOpt.SizeOf = Marshal.SizeOf(typeof(WALLPAPEROPT)); IntPtr programWindow = User32.FindWindow("Progman", null); User32.SendMessage(programWindow, 0x52c, IntPtr.Zero, IntPtr.Zero); IActiveDesktop activeDesktop = ActiveDesktop.Create(); activeDesktop.SetWallpaper(file, 0); activeDesktop.SetWallpaperOptions(ref wallpaperOpt, 0); activeDesktop.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH); }
private static void _downloader_WallpaperChanged(object sender, WallpaperChangedEventArgs e) { //NativeMethods.SystemParametersInfo(NativeMethods.SPI_SETDESKWALLPAPER, 0, Path.GetFullPath(filename), // NativeMethods.SPIF_UPDATEINIFILE | NativeMethods.SPIF_SENDCHANGE); _mainForm.Invoke((MethodInvoker) delegate { IActiveDesktop iad = shlobj.GetActiveDesktop(); iad.SetWallpaper(Path.GetFullPath(e.WallpaperFilePath), 0); if (Environment.OSVersion.Version >= new Version(6, 1)) { var options = new WALLPAPEROPT { dwSize = WALLPAPEROPT.SizeOf, dwStyle = WallPaperStyle.WPSTYLE_CROPTOFIT }; iad.SetWallpaperOptions(options, 0); } iad.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH); Marshal.ReleaseComObject(iad); }); }
public static void SetWallpaper(string imagePath) { EnableTransitions(); ThreadStart threadStarter = () => { IActiveDesktop _activeDesktop = ActiveDesktopWrapper.GetActiveDesktop(); _activeDesktop.SetWallpaper(imagePath, 0); _activeDesktop.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE); Marshal.ReleaseComObject(_activeDesktop); }; Thread thread = new Thread(threadStarter); thread.SetApartmentState(ApartmentState.STA); // Set the thread to STA (required!) thread.Start(); thread.Join(2000); if (UwpDesktop.IsRunningAsUwp()) // Ensure wallpaper registry setting gets updated { UpdateRegistrySettings(imagePath); } }
private void ProduceThread() { IActiveDesktop ad = (IActiveDesktop) new ActiveDesktop(); _signal.Set(); while (true) { _signal.WaitOne(); Job query; while (_queue.TryDequeue(out query)) { object retval = null; dynamic input = query.input; try { switch (query.method_idx) { case 0: ad.ApplyChanges((uint)input.dwFlags); break; case 1: retval = StringDelegate((b) => ad.GetWallpaper(b, (uint)b.Capacity, (uint)input.dwFlags)); break; case 2: ad.SetWallpaper((string)input.pwszWallpaper); break; case 3: ad.GetWallpaperOptions((WallpaperOpt)(retval = new WallpaperOpt())); break; case 4: ad.SetWallpaperOptions(new WallpaperOpt((dynamic)input.pwpo)); break; case 5: retval = StringDelegate((b) => ad.GetPattern(b, (uint)b.Capacity)); break; case 6: ad.SetPattern((string)input.pwszPattern); break; case 7: ad.GetDesktopItemOptions((ComponentsOpt)(retval = new ComponentsOpt())); break; case 8: ad.SetDesktopItemOptions(new ComponentsOpt((dynamic)input.pco)); break; case 9: ad.AddDesktopItem(new Component((dynamic)input.pcomp)); break; case 10: ad.AddDesktopItemWIthUI((IntPtr)input.hwnd, new Component((dynamic)input.pcomp), (uint)input.dwFlags); break; case 11: ad.ModifyDesktopItem((Component)(retval = new Component((dynamic)input.pcomp)), (uint)input.dwFlags); break; case 12: ad.RemoveDesktopItem(new Component((dynamic)input.pcomp)); break; case 13: int pcItems; ad.GetDesktopItemCount(out pcItems); retval = pcItems; break; case 14: ad.GetDesktopItem((int)input.nComponent, (Component)(retval = new Component((dynamic)input.pcomp))); break; case 15: ad.GetDesktopItemByID((ulong)input.dwID, (Component)(retval = new Component((dynamic)input.pcomp))); break; case 16: ad.GenerateDesktopItemHtml((string)input.pwszFileName, new Component((dynamic)input.pcomp)); break; case 17: ad.AddUrl((IntPtr)input.hwnd, (string)input.pszSource, new Component((dynamic)input.pcomp), (uint)input.dwFlags); break; case 18: ad.GetDesktopItemBySource((string)input.pszSource, (Component)(retval = new Component((dynamic)input.pcomp))); break; } query.retval = retval; } catch (Exception e) { query.e = e; } query._signal.Set(); } } }
// -------------------------------------------------------------------- public void SetImageAsWellpaper() { activeDesktop.SetWallpaper(fileName, 0); activeDesktop.ApplyChanges(AD_Apply.ALL); }