Change windows wallpaper using .NET 4.0?

Is there a way to change windows wallpapers with some new feature in .NET 4?

+5
source share
3 answers

You can use SystemParametersInfo to set the desktop wallpaper. This should work consistently in all versions of windows that can run in your application, however, this will require several interactions.

The following are interop ads.

public const int SPI_SETDESKWALLPAPER = 20;
public const int SPIF_UPDATEINIFILE = 1;
public const int SPIF_SENDCHANGE = 2;

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SystemParametersInfo(
  int uAction, int uParam, string lpvParam, int fuWinIni);

What can be used to change desktop wallpaper

SystemParametersInfo(
  SPI_SETDESKWALLPAPER, 0, "filename.bmp", 
  SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
+8
source

Note that SystemParametersInfo will even return true if the specified file does not exist! (at least on Windows 8)

In addition, you must specify the full path to the file, not just the relative path.

Also on windows 7 and above this will create a new theme and, of course, turn off image shuffling.

0
source

All Articles