Violet Giraffe
Violet Giraffe

Reputation: 33605

Setting wallpaper with Win API

I want to programmatically set a wallpaper. Here's the only solution I've found so far:

SystemParametersInfoW(SPI_SETDESKWALLPAPER, 1, (void*)wallpaperImageFilePath.utf16(), SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);

My question is: how to tell Windows I want the wallpaper image centered (not resized)? The solution above always sets the image in stretch mode. According to MSDN, there are no flags to accompany SPI_SETDESKWALLPAPER.

Upvotes: 3

Views: 13628

Answers (2)

theB
theB

Reputation: 6738

As of Windows 8 there is now a published interface for setting the desktop background. Specifically the IDesktopBackground::SetWallpaper method. MSDN Documentation

The interface also has several methods for getting and setting the configuration of the slideshow, and obtaining the required monitor device paths.

Upvotes: 13

Remy Lebeau
Remy Lebeau

Reputation: 598029

There is no API function for setting the wallpaper orientation. You have to go to the Registry directly instead, specifically the "WallpaperStyle" and "TileWallpaper" values of the HKEY_CURRENT_USER\Control Panel\Desktop key. See this article for an example:

Set the desktop wallpaper (CppSetDesktopWallpaper)

Upvotes: 6

Related Questions