Matthew van Eerde's web log
I am a Software Development Engineer in Test working for the Windows Sound team. You can contact me via email: mateer at microsoft dot com
Friend key:28904932216450_59cd9d55374be03d8167d37c8ff4196b
Working on Windows, I find myself installing Windows a lot.
I find that I like to change a lot of the settings that Windows offers to non-default values. (That is, I'm picky.)
I have a script which automates some of these things, which I add to now and again. Some of the bits of the script are straightforward, but once in a while the tweak itself is of interest.
One of the things I love about my work setup is the many large monitors. So, one of the things I like to change is the desktop wallpaper image.
Changing the desktop wallpaper required some code, which makes it "of interest." Here's the code.
// main.cpp
#include <windows.h>#include <winuser.h>#include <stdio.h>
int _cdecl wmain(int argc, LPCWSTR argv[]) { if (1 != argc - 1) { wprintf(L"expected a single argument, not %d\n", argc); return -__LINE__; } if (!SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, const_cast<LPWSTR>(argv[1]), SPIF_SENDCHANGE )) { DWORD dwErr = GetLastError(); wprintf(L"SystemParametersInfo(...) failed with error %d\n", dwErr); return -__LINE__; } wprintf(L"Setting the desktop wallpaper to %s succeeded.\n", argv[1]); return 0;}
Binaries attached.
Warning: if you pass a relative path to this tool, it won't qualify it for you, and the SystemParametersInfo call won't either - so the wallpaper you want won't be set, though all the calls will succeed. Make sure to specify a fully-qualified path.