Reputation: 100322
Is there a way to change the Windows wallpaper using some new feature in .NET 4?
Upvotes: 5
Views: 5267
Reputation: 1420
Note that SystemParametersInfo will even return true, if the specified file does not exist! (on Windows 8 at least)
Plus you must give the full path to the file, not just a relative path.
Also on windows 7 and above this will create a new theme, and will turn off picture shuffling of course.
Upvotes: 0
Reputation: 53699
You can use SystemParametersInfo to set the desktop wallpaper. This should work consistently on all versions of windows that your app can run on, however will require some interop.
The following interop declarations are what you need
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);
Which can be used like this to change the desktop wallpaper
SystemParametersInfo(
SPI_SETDESKWALLPAPER, 0, "filename.bmp",
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
Upvotes: 8
Reputation: 89082
You set the wallpaper by updating the registry. Here's an article from 2006 explaining how to do it. The details may have changed with newer versions of Windows, but the concept should be the same. Framework version should be irrelevant.
http://blogs.msdn.com/coding4fun/archive/2006/10/31/912569.aspx
Upvotes: 1