I am looking to change the Windows desktop background wallpaper in C++ using the Windows API.
I have read the following posts on this topic:
- How to change desktop background using VC++
- SystemParametersInfo sets wallpaper completly black (using SPI_SETDESKWALLPAPER)
Problem:
When I execute the code, the desktop background changes to completely black like in the post above (yes, I did try the suggested fix in that post. No luck.)
Code:
#include <windows.h>
int main() {
std::string s = "C:\\picture.jpg";
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID*)s.c_str(), SPIF_SENDCHANGE);
return 0;
}
I have also tried just (void*)
instead of (PVOID*)
above and an L
in front of the string. Nothing works so far.
SOLVED:
Changing SystemParametersInfo
to SystemParametersInfoA
(as suggested in the comment and answer) did the trick.