次のコードを使用してデスクトップの壁紙を設定する際に問題があります。SystemParametersInfo は true を返しますが、壁紙は変更されません。以前と変わらずそのままです。しかし、コードで *.bmp ファイルのディレクトリから定期的に壁紙を変更する必要があります。どこが間違っているのか教えてください。
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:/users/Smart-PC/Desktop");
images = dirInfo.GetFiles("*.bmp", SearchOption.TopDirectoryOnly);
currentImage = 0;
System.Timers.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 = 30;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;
bool gk;
gk = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, images[currentImage++].FullName, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
Console.Write(gk);
Console.WriteLine(images[currentImage].FullName);
currentImage = (currentImage >= images.Length) ? 0 : currentImage;
}
}