我使用此代码删除当前壁纸并设置纯色:
public static class WallpaperColorChanger
{
public static void SetColor(Color color)
{
// Remove the current wallpaper
NativeMethods.SystemParametersInfo(
NativeMethods.SPI_SETDESKWALLPAPER,
0,
"",
NativeMethods.SPIF_UPDATEINIFILE | NativeMethods.SPIF_SENDWININICHANGE);
// Set the new desktop solid color for the current session
int[] elements = { NativeMethods.COLOR_DESKTOP };
int[] colors = { System.Drawing.ColorTranslator.ToWin32(color) };
NativeMethods.SetSysColors(elements.Length, elements, colors);
// Save value in registry so that it will persist
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Colors", true);
key.SetValue(@"Background", string.Format("{0} {1} {2}", color.R, color.G, color.B));
}
private static class NativeMethods
{
public const int COLOR_DESKTOP = 1;
public const int SPI_SETDESKWALLPAPER = 20;
public const int SPIF_UPDATEINIFILE = 0x01;
public const int SPIF_SENDWININICHANGE = 0x02;
[DllImport("user32.dll")]
public static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
}
}
但是,如果启用了 Windows 7 幻灯片功能并且壁纸每 30 分钟更改一次,那么当我运行代码时,它会将壁纸更改为纯色,但当我重新启动计算机时,它会恢复壁纸和幻灯片功能。
为了在重新启动计算机后仍保持纯色,我还必须做什么?
我正在使用 C#、Windows 窗体、Windows 7。