1

I have tried all of the solution specified on these posts:

  1. How to change the windows 10 wallpaper with C++?
  2. How to change desktop background using VC++
  3. SystemParametersInfo sets wallpaper completly black (using SPI_SETDESKWALLPAPER)

And i still cant seem to be able to get it working.... heres my code:

const wchar_t* path = L"C:\\imagge.png";
bool result = SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void*)path, SPIF_UPDATEINIFILE);
std::cout << result;

Also if i specify a path that aint valid it still prints 1(true) when it clearly states on docs SPI_SETDESKWALLPAPER bit that it should return 0(false) if theirs a problem

Also i have tried calling printing out GetLastError(); and it returns 0....

Note When the SPI_SETDESKWALLPAPER flag is used, SystemParametersInfo returns TRUE unless there is an error (like when the specified file doesn't exist).

1 Answers1

2

IInspectable suggested using IDesktopWallpaper interface

And i got it working!

Heres my code:

int main() {
std::wstring x = L"C:\\Users\\danie\\OneDrive\\Pictures\\pixelArt\\Sample.png";
HRESULT  ad;
CoInitialize(NULL);

IDesktopWallpaper* p;
if(SUCCEEDED(CoCreateInstance(__uuidof(DesktopWallpaper), 0, CLSCTX_LOCAL_SERVER, __uuidof(IDesktopWallpaper), (void**)&p))) {
    ad = p->SetWallpaper(NULL, x.c_str());
    p->Release();
}

CoUninitialize();
return 0;
}