Notify Windows Explorer that a wallpaper has been changed

215 views Asked by At

I wrote an app that changes the Windows wallpaper by registry, but I need to notify Explorer.exe so I can see the new background. I tried using SendMessageTimeoutW:

SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE,
                                        0, 0, SMTO_ABORTIFHUNG, 5000, NULL);

However, it did not work. Any function I can use?

2

There are 2 answers

4
Matteo Italia On BEST ANSWER

Don't modify the windows registry directly for this kind of settings; the correct way to modify the wallpaper is to call the SystemParametersInfo API, passing SPI_SETDESKWALLPAPER, passing the path to the wallpaper in pvParam and SPIF_UPDATEINIFILE | SPIF_SENDCHANGE in fWinIni (which makes the modification permanent).

0
Sergio Calderon On

As Matteo suggested, I used the SystemParametersInfo function to set the wallpaper like this:

BOOL setDesk = SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, L"C:\\MyWall.jpg", SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);

But It only works on a local environment, not in a domain one. I had to set the wallpaper by modifying the registry and then used the same function to just notify Windows about the change:

BOOL setDesk = SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);