Reputation: 3072
I am writing a program that needs to know when the desktop wallpaper changes. After some searching, I found a partial solution: http://www.neowin.net/forum/topic/567779-net-detect-wallpaper-change/
Essentially, it says to listen for the WM_SETTINGCHANGE
message, and check the wallpaper. Unfortunately, this message does not appear to be sent when the wallpaper is changed as a result of the Windows 7 wallpaper slideshow. In fact, no message seems to be sent to my application at all for this (the only time I've ever seen WndProc
not get constant messages :)).
So my question is, short of polling the registry and wallpaper file for changes, is there a way to detect when this happens? Does anyone know where I can find API docs that list what function gets called?
Upvotes: 4
Views: 7057
Reputation: 11
I have an idea better, little time ago I written little program that automatically changes my background on the LogonScreen and wanted to improve this with ability to automatically detect what wallpaper is on the background and set the same when windows changing my background. So, I started my investigation and found:
So, algorithm is the following:
Upvotes: 1
Reputation: 3072
Actually I figured out a workaround to the issue. There's actually a registry notification mechanism, so it's possible to raise an event when a specified key/value changes.
HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper
is the key. This doesn't get changed when the slideshow changes the wallpaper, but the file at that location does change. By monitoring the file for changes you can actually be notified of this change.
Incidentally, the whole point of the app I was coding relied on that, so omitting it wouldn't be an option :).
Thanks for your reply though - helped put my conscience to rest in regards to having to go through such a roundabout way of doing things.
Upvotes: 2
Reputation: 244843
This is a good question, and I left it unanswered for a while to see if anyone knew something that I didn't.
But unfortunately, I think you're going to discover that it's not possible to receive notification messages corresponding to this event. The wallpaper slideshow doesn't actually change the system theme or any of the system settings, so a WM_SETTINGCHANGE
message doesn't get sent. It's designed to happen in the background and not require that any application be notified. If the user has selected the "slideshow" option, it's reasonable to assume that they expect the background to be changed at periodic intervals, no interaction or notification necessary. In short, in at least 99% of cases, your application should not respond any differently as a result of wallpaper changes arising from the slideshow option.
The best thing I can think of is to determine the interval they've specified at which the wallpaper should be changed, and then have your application respond accordingly when that time has elapsed. Essentially, you'll have to create and respond to your own notifications.
Polling the registry is to be strongly discouraged. Not only is that completely undocumented and thus subject to breaking on future versions of Windows (or even Windows updates!), but it's also not a reliable indicator. If there's any alternative (including omitting the functionality altogether), that's the path that I would take.
Upvotes: 2