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); } }
public static IDesktopWallpaper GetDesktopWallpaperAPI() { try { var result = DesktopWallpaperFactory.Create(); return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); return(null); } }
private void BtnTest_Click(object sender, RoutedEventArgs e) { var test0 = System.Windows.Forms.Screen.AllScreens; var test = User32WrapperEx.GetDisplays(); var test2 = User32WrapperEx.Display(); var desktopFactory = DesktopWallpaperFactory.Create(); desktopFactory.GetSlideshowOptions(out DesktopSlideshowOptions options, out uint slide); desktopFactory.SetSlideshowOptions(DesktopSlideshowOptions.DSO_SHUFFLEIMAGES, 1000 * 60); desktopFactory.SetSlideshowOptions(DesktopSlideshowOptions.DSO_SHUFFLEIMAGES, 1000 * 60 * 60 * 24); desktopFactory.GetSlideshowOptions(out DesktopSlideshowOptions option1s, out uint sli1de); }
public static Tuple <Color, string> GetCurrentColorAndWallpaper() { var dw = DesktopWallpaperFactory.Create(); var colorref = dw.GetBackgroundColor(); string path = null; if (dw.GetMonitorDevicePathCount() >= 1) { var monitorId = dw.GetMonitorDevicePathAt(0); path = dw.GetWallpaper(monitorId); } return(Tuple.Create(Color.FromRgb(colorref.R, colorref.G, colorref.B), path)); }
private void Set(WallpaperFile[] files) { var dw = DesktopWallpaperFactory.Create(); var pathes = Enumerable.Range(0, (int)dw.GetMonitorDevicePathCount()).Select(idx => dw.GetMonitorDevicePathAt((uint)idx)).ToArray(); var merged = files.Length == pathes.Length ? pathes.Zip(files, (f, p) => Tuple.Create(f, p)).ToList() : Enumerable.Repeat(files[0], pathes.Length).Zip(pathes, (p, f) => Tuple.Create(f, p)).ToList(); merged.ForEach(i => dw.SetWallpaper(i.Item1, i.Item2.Filepath)); var first = merged.First(); if (first != null) { dw.SetPosition((DesktopWallpaperPosition)first.Item2.Position); } }
public ImageRender() : base(WallpaperType.Image, new List <string>() { ".jpg", ".jpeg", ".png", ".bmp" }, false) { _desktopFactory = DesktopWallpaperFactory.Create(); }
public static void ResetDesktopWallpaperAPI() { DesktopWallpaperAPI = DesktopWallpaperFactory.Create(); }