问题描述
我正在编写一个程序,它需要知道桌面墙纸何时发生变化.经过一番搜索,我找到了部分解决方案:http://www.neowin.net/forum/topic/567779-net-detect-wallpaper-change/
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/
基本上,它说要监听 WM_SETTINGCHANGE
消息,然后查看壁纸.不幸的是,当由于 Windows 7 壁纸幻灯片放映而更改壁纸时,似乎不会发送此消息.事实上,似乎根本没有向我的应用程序发送任何消息(这是我唯一一次看到 WndProc
not 收到持续的消息:)).
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 :)).
所以我的问题是,没有轮询注册表和壁纸文件以进行更改,有没有办法检测何时发生这种情况?有谁知道我在哪里可以找到列出调用什么函数的 API 文档?
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?
推荐答案
其实我想出了一个解决这个问题的方法.实际上有一个注册表通知机制,因此可以在指定的键/值更改时引发事件.HKEY_CURRENT_USERControl PanelDesktopWallpaper
是关键.当幻灯片更改墙纸时,这不会更改,但该位置的文件确实会更改.通过监视文件的更改,您实际上可以收到有关此更改的通知.
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_USERControl PanelDesktopWallpaper
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.
这篇关于如何检测由于 Windows 7 幻灯片放映而导致的墙纸变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!