Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
            }
        }