【问题标题】:Slideshow Wallpaper Windows 7幻灯片壁纸 Windows 7
【发布时间】:2012-07-05 08:00:08
【问题描述】:

如何以编程方式设置 Windows 7 壁纸幻灯片?

设置普通壁纸

    [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, 0, filename, SPIF_UPDATEINIFILE);
        }

到目前为止我发现了什么:

幻灯片中有一个ini文件

C:\Users\CurrentUser\AppData\Roaming\Microsoft\Windows\Themes\

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

C:\Users\CurrentUser\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper.jpg

(在幻灯片放映期间文件会自动更改)

【问题讨论】:

  • 您找到解决方案了吗?我也面临同样的问题。
  • @DTI-Matt 到目前为止还没有

标签: c# windows c#-4.0 windows-7 wallpaper


【解决方案1】:

试试这个

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 Panel\Desktop", 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());
        key.SetValue(@"TileWallpaper", 1.ToString());
    }

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

原问题是this

【讨论】:

  • 使用计时器:private void timer_Tick(object sender, EventArgs e) { // 你的代码更改图像每... }
  • 我想做的是:使用内置幻灯片壁纸的窗口,而不是让应用程序一直在后台运行!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-04
  • 2014-05-28
  • 2011-07-10
  • 1970-01-01
  • 2016-12-11
  • 2011-07-29
相关资源
最近更新 更多