How can I detect wallpaper changing as a result of the Windows 7 slideshow?

半城伤御伤魂 提交于 2019-12-30 01:37:51

问题


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?


回答1:


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.




回答2:


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.




回答3:


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:

  1. %USERDIR%\AppData\Roaming\Microsoft\Windows\Themes - place for current transcoded image from bg and slideshow.ini that contains little bit of info about current Theme
  2. %USERDIR%\AppData\Local\Microsoft\Windows\Themes - folder that contains themes installed on this system

So, algorithm is the following:

  1. read slideshow.ini and get value under [Slideshow]
  2. read all theme files and compare [Slideshow] value of each theme and if it's equal - we found current theme file
  3. from file of current theme read value of Interval=1800000 (in my case it's 30 min) (BTW, interval placed after [Slideshow], so it's can be done in the same iteration of lines)
  4. Read modify time from current image on bg: %USERDIR%\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper.jpg
  5. So, we have time of next changing (current_time - modify_time + Interval) and can execute any code at Wallpaper changing (also do not forget catch situations if settings changed or changing is disabled - because it's can cause an exceptions, as improving we can recheck this file every minute or something like this)
  6. And if you will try to write the same program, do not forget compress image size, because it's requires 256Kb max.


来源:https://stackoverflow.com/questions/5537836/how-can-i-detect-wallpaper-changing-as-a-result-of-the-windows-7-slideshow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!