views:

140

answers:

3

I have figured out how to change the desktop wallpaper (there are dozens of examples on the Internet.)

One thing that still eludes me: how do I detect when the wallpaper has changed? (Say via the Display control panel or another program changing it.)

+3  A: 

Here is an example in C# to retrieve the wallpaper. All you would need to add is some additional code to store the last wallpaper and check to see if it is different.

RegistryKey wallpaper = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop",false);
string wallpapername = wallpaper.GetValue("wallpaper").ToString();          
wallpaper.Close();

If you were writing something in a non .net language you could use the Win32API RegNotifyChangeKeyValue to check to see if this value has changed

HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper

Aaron M
+5  A: 

Add a message handler for WM_SETTINGCHANGE, SystemEvents.UserPreferenceChanged in .NET. Check if the wallpaper is still the same.

Hans Passant
It's `WM_SETTINGCHANGE`, but yes, I would say that this is a good way to be notified.
Aaron Klotz
+1  A: 

Thanks all!

I dont know how to mark an answer as correct/accepted - so if someone wants to mark nobugz as the way to go - that'd be good.

boogaloo