我试图自动更改桌面墙纸每5分钟(为了调试目的,它被配置为5秒)。自动桌面墙纸更换
我发现了一些标准的方法从.net代码调用SystemParametersInfo()API与它的标准参数。
我做到了。但是我发现它只拾取Bmp文件。我有一大堆我喜欢放在桌面上的JPG。
那么我发现了一些建议,使用Image.Save()方法将JPG转换为Bmp。我不喜欢这个。
什么是在桌面上设置Jpg的直接方法?我猜User32.dll应该提供一个方法。
这是给你参考代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Timers;
namespace ChangeWallpaper
{
class Program
{
[DllImport("user32.dll")]
public static extern bool SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, string pvParam, UInt32 fWinIni);
static FileInfo[] images;
static int currentImage;
static void Main(string[] args)
{
DirectoryInfo dirInfo = new DirectoryInfo(@"C:\TEMP");
images = dirInfo.GetFiles("*.jpg", SearchOption.TopDirectoryOnly);
currentImage = 0;
Timer imageChangeTimer = new Timer(5000);
imageChangeTimer.Elapsed += new ElapsedEventHandler(imageChangeTimer_Elapsed);
imageChangeTimer.Start();
Console.ReadLine();
}
static void imageChangeTimer_Elapsed(object sender, ElapsedEventArgs e)
{
const uint SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, images[currentImage++].FullName, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
currentImage = (currentImage >= images.Length) ? 0 : currentImage;
}
}
}
也很有用:http://www.blackwasp.co.uk/Wallpaper.aspx – prasanthv 2013-05-03 02:27:20