Setting wallpaper with Win API

≡放荡痞女 提交于 2019-12-02 05:00:13

问题


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.


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/14186400/setting-wallpaper-with-win-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!