我正在制作一个简单的壁纸更换器。它在更换壁纸时有效,但我无法更改壁纸的图案。我试过这样的东西,但它不起作用:S
SystemParametersInfo(SPI_SETDESKPATTERN, 0, "Center",
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
有人可以告诉我设置壁纸图案的正确方法吗?
我正在制作一个简单的壁纸更换器。它在更换壁纸时有效,但我无法更改壁纸的图案。我试过这样的东西,但它不起作用:S
SystemParametersInfo(SPI_SETDESKPATTERN, 0, "Center",
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
有人可以告诉我设置壁纸图案的正确方法吗?
我假设您的意思是居中/拉伸/平铺设置,这将是第二个过去值 int 1-3
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 action, UInt32 uParam, String vParam, UInt32 winIni);
private static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14;
private static readonly UInt32 SPIF_UPDATEINIFILE = 0x01;
private static readonly UInt32 SPIF_SENDWININICHANGE = 0x02;
private void SetWallpaper(string path)
{
if (File.Exists(path))
{
Image imgInFile = Image.FromFile(path);
try
{
imgInFile.Save(SaveFile, ImageFormat.Bmp);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 3, SaveFile, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
catch
{
MessageBox.Show("error in setting the wallpaper");
}
finally
{
imgInFile.Dispose();
}
}
}