/// <summary> /// Creates a new ScreenSettings instance. /// </summary> /// <param name="screenID">screen id</param> /// <param name="checksum">checksum</param> /// <param name="wallpaperPath">wallpaper path</param> /// <param name="backgroundColor">background color</param> /// <param name="style">style</param> public ScreenSettings(string screenID, string checksum, string wallpaperPath, Color backgroundColor, WallPaperStyle style) { ScreenID = screenID; Checksum = checksum; BackgroundColor = backgroundColor; WallpaperPath = wallpaperPath; Style = style; }
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"); } }
/// <summary> /// Sets the users desktop wallpaper to the specified image, with the specified style. /// </summary> /// <param name="sDirectory">Specifies the directory path of the background image copy to be saved in.</param> /// <param name="oImage">Specifies the image to set as the desktop wallpaper.</param> /// <param name="nStyle">Specifies the wallpaper style.</param> public static int SetDesktopBackground(string sDirectory, Image oImage, WallPaperStyle nStyle) { try { if ((oImage != null) && (!string.IsNullOrEmpty(sDirectory))) { sDirectory += Path.DirectorySeparatorChar; bool bSave = false; string sFilePath = string.Empty; DirectoryInfo oDirectory = new DirectoryInfo(sDirectory); // Create the directory if it doesn't exist. if (!oDirectory.Exists) oDirectory.Create(); // Generate a file path. for (int n = 0; n < MAX_FILES; n++) { sFilePath = sDirectory + FILE_NAME_PREFIX + n.ToString("x4") + ".bmp"; if (!File.Exists(sFilePath)) { bSave = true; break; } } // Save the image and set the desktop background. if (bSave) { using (Bitmap oBitmap = new Bitmap(oImage)) oBitmap.Save(sFilePath, System.Drawing.Imaging.ImageFormat.Bmp); RegistryKey oKey = Registry.CurrentUser.OpenSubKey(RKEY_DESKTOP, true); switch (nStyle) { case WallPaperStyle.Center: oKey.SetValue("WallpaperStyle", "1"); oKey.SetValue("TileWallpaper", "0"); break; case WallPaperStyle.Stretch: oKey.SetValue("WallpaperStyle", "2"); oKey.SetValue("TileWallpaper", "0"); break; case WallPaperStyle.Tile: oKey.SetValue("WallpaperStyle", "1"); oKey.SetValue("TileWallpaper", "1"); break; } oKey.Flush(); oKey.Close(); return SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, sFilePath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); } } } catch (System.Security.SecurityException e) { MessageBox.Show(e.Message, "SecurityException", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (IOException e) { MessageBox.Show(e.Message, "IOException", MessageBoxButtons.OK, MessageBoxIcon.Error); } return 0; }
/// <summary> /// Creates a new StyleMenuItem instance. /// </summary> /// <param name="text">item text</param> /// <param name="value">item value</param> public StyleMenuItem(string text, WallPaperStyle value) : this() { Text = text; Value = value; }
/// <summary> /// iView.NET subroutine. Sets the currently selected image as the desktop wallpaper. /// </summary> /// <param name="nStyle">Specifies the style for the wallpaper.</param> /// <returns></returns> private SResult SubSetWallPaper(WallPaperStyle nStyle) { if (imgbx_MainImage.IsImageLoaded) { NativeMethods.SetDesktopBackground(ApplicationData.BackgroundsFolder, imgbx_MainImage.ImageBoxImage, nStyle); return SResult.Completed; } return SResult.NullDisplayImage; }