Example #1
0
        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");
            }
        }
Example #2
0
        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);
        }