예제 #1
0
        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);
            }
        }
예제 #2
0
 public static IDesktopWallpaper GetDesktopWallpaperAPI()
 {
     try
     {
         var result = DesktopWallpaperFactory.Create();
         return(result);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex);
         return(null);
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
 public ImageRender() : base(WallpaperType.Image, new List <string>() { ".jpg", ".jpeg", ".png", ".bmp" }, false)
 {
     _desktopFactory = DesktopWallpaperFactory.Create();
 }
예제 #7
0
 public static void ResetDesktopWallpaperAPI()
 {
     DesktopWallpaperAPI = DesktopWallpaperFactory.Create();
 }