zoukankan      html  css  js  c++  java
  • C# 设置桌面壁纸 Desktop wallpaper

      public static class Wallpaper
      {
            const int SPI_SETDESKWALLPAPER = 20;
            const int SPIF_UPDATEINIFILE = 0x01;
            const int SPIF_SENDWININICHANGE = 0x02;
    
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
    
            public enum Style : int
            {
                Fill,
                Fit,
                Span,
                Stretch,
                Tile,
                Center
            }
    
    
            private static void SetWallPaper(string wpaper, Style style)
            {
                using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control PanelDesktop", true))
                {
                    if (style == Style.Fill)
                    {
                        key.SetValue(@"WallpaperStyle", 10.ToString());
                        key.SetValue(@"TileWallpaper", 0.ToString());
                    }
                    if (style == Style.Fit)
                    {
                        key.SetValue(@"WallpaperStyle", 6.ToString());
                        key.SetValue(@"TileWallpaper", 0.ToString());
                    }
                    if (style == Style.Span) // Windows 8 or newer only!
                    {
                        key.SetValue(@"WallpaperStyle", 22.ToString());
                        key.SetValue(@"TileWallpaper", 0.ToString());
                    }
                    if (style == Style.Stretch)
                    {
                        key.SetValue(@"WallpaperStyle", 2.ToString());
                        key.SetValue(@"TileWallpaper", 0.ToString());
                    }
                    if (style == Style.Tile)
                    {
                        key.SetValue(@"WallpaperStyle", 0.ToString());
                        key.SetValue(@"TileWallpaper", 1.ToString());
                    }
                    if (style == Style.Center)
                    {
                        key.SetValue(@"WallpaperStyle", 0.ToString());
                        key.SetValue(@"TileWallpaper", 0.ToString());
                    }
                }
    
                SystemParametersInfo(SPI_SETDESKWALLPAPER,
                        0,
                        wpaper,
                        SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
            }
     }

    传入图片路径即可

  • 相关阅读:
    (转)matlab 字符串处理函数
    (原)不明白JNI指针调用顺序
    (转)几种平均数的关系:
    (原+转)继承与虚函数
    (原)给定输入,输出全排列
    (转)发现两个有用的C函数_alloca()、_msize()
    (原)android的JNI中使用C++的类
    (原+转)C++中的const修饰符
    (转)C/C++中static关键字
    JAVA IO 对象流
  • 原文地址:https://www.cnblogs.com/xyz0835/p/9277609.html
Copyright © 2011-2022 走看看