加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 幻灯片壁纸Windows 7

发布时间:2020-12-15 18:34:28 所属栏目:百科 来源:网络整理
导读:如何以编程方式设置 Windows 7 Wallpaper幻灯片? 设置普通壁纸 [DllImport("user32.dll",CharSet = CharSet.Auto)] private static extern Int32 SystemParametersInfo(UInt32 uiAction,UInt32 uiParam,String pvParam,UInt32 fWinIni); private static UIn
如何以编程方式设置 Windows 7 Wallpaper幻灯片?

设置普通壁纸

[DllImport("user32.dll",CharSet = CharSet.Auto)]
        private static extern Int32 SystemParametersInfo(UInt32 uiAction,UInt32 uiParam,String pvParam,UInt32 fWinIni);
        private static UInt32 SPI_SETDESKWALLPAPER = 20;
        private static UInt32 SPIF_UPDATEINIFILE = 0x1;
  public void SetImage(string filename)
        {
            SystemParametersInfo(SPI_SETDESKWALLPAPER,filename,SPIF_UPDATEINIFILE);
        }

我到现在才发现:

幻灯片中有一个ini文件

C:UsersCurrentUserAppDataRoamingMicrosoftWindowsThemes

幻灯片放映期间,壁纸必须位于以下文件夹中:

C:UsersCurrentUserAppDataRoamingMicrosoftWindowsThemesTranscodedWallpaper.jpg

(during a slideshow the file is changing automatically)

解决方法

试试这个
public sealed class Wallpaper
{
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
{
    Tiled,Centered,Stretched
}

public static void Set(Uri uri,Style style)
{
    System.IO.Stream s = new System.Net.WebClient().OpenRead(uri.ToString());

    System.Drawing.Image img = System.Drawing.Image.FromStream(s);
    string tempPath = Path.Combine(Path.GetTempPath(),"wallpaper.bmp");
    img.Save(tempPath,System.Drawing.Imaging.ImageFormat.Bmp);

    RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control PanelDesktop",true);
    if (style == Style.Stretched)
    {
        key.SetValue(@"WallpaperStyle",2.ToString());
        key.SetValue(@"TileWallpaper",0.ToString());
    }

    if (style == Style.Centered)
    {
        key.SetValue(@"WallpaperStyle",1.ToString());
        key.SetValue(@"TileWallpaper",0.ToString());
    }

    if (style == Style.Tiled)
    {
        key.SetValue(@"WallpaperStyle",1.ToString());
    }

    SystemParametersInfo(SPI_SETDESKWALLPAPER,tempPath,SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
 }

最初的问题是this

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读