views:

6708

answers:

5

On X Windows I had a cool 'silent-alarm" reminder script that would change my root window (background) color to solid red, just for a few seconds a few moments before changing it back. Is there a way to do this for Windows XP?

I'm thinking some kind of scheduled task that uses cscript to set registry keys (HKEY_CURRENT_USER\Control Panel\Desktop) . However my attempts don't seem to have any effect. What do I have to signal to read those registry entries and re-draw the desktop?

A: 

You're probably on the right course, but you need to then force a re-evaluation of that key. Though there's likely a Win32 function that will do what you want and wouldn't rely on implementation details.

Orion Adrian
+1  A: 

Have a look at the oddly named SystemParametersInfo function, in particular the SP_SETDESKPATTERN subfunction. This may do what you want, and if not, there's probably some other subfunction in there that will.

Greg Hewgill
+1  A: 

this isn't as cool as actually spending time writing code, but there's a pretty useful system util called bginfo that embeds info into the desktop's background. it's fairly configurable with all sorts of command-line options. no, i didn't write it.

david dickey
+1  A: 

According to MSDN:

PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETDESKWALLPAPER, 0);

This is listed for Windows Mobile, but it might should work in desktop Windows. Also note that it must be a .BMP image format to absolutely work, even though some Windows versions take .JPG format also.

After further research, it seems that SystemParametersInfo will do the combination of changing the user profile and registry keys, and posting the necessary message to effect the change.

void setWallpaper(const char * const PATH_TO_BMP)
{
    /* I'm not sure whether the SPIF_UPDATEINIFILE is necessary
       to make the change persistant. It indicates that the
       user's profile should be updated with the changed
       information. The SPIF_SENDCHANGE is definitely necessary
       in order to immediately effect the change without restart. */
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PATH_TO_BMP, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
jdmichal
+4  A: 

I think that once you modify the wallpaper setting in the registry, you simply need to run

RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters

from the command line and the changes should take effect. You need to make sure that your image is a bmp file.

In fact, I just tried this by creating a desktop sized bmp file that was all red. I changed the //HKCU/control panel/desktop/wallpaper key to contain the full pathname to this bitmap. I ran the above command from the command line and the desktop changed to the red bmp that I just created

Mark
works fine for me to remove the image, but when I tried to change the Background color in "HKCU\Control Panel\Colors\Background" it does not do it.
Peter Hahndorf