如何检测因 Windows 7 幻灯片放映而导致的壁纸变化?
我正在编写一个程序,需要知道桌面壁纸何时发生变化。经过一番搜索,我找到了部分解决方案: http://www.neowin.net/forum/topic/ 567779-net-detect-wallpaper-change/
本质上,它表示监听 WM_SETTINGCHANGE
消息,然后检查壁纸。不幸的是,当由于 Windows 7 壁纸幻灯片放映而更改壁纸时,似乎不会发送此消息。事实上,似乎根本没有消息被发送到我的应用程序(这是我唯一一次看到 WndProc
没有收到持续的消息:))。
所以我的问题是,除了轮询注册表和壁纸文件以进行更改之外,有没有办法检测到这种情况何时发生?有谁知道我在哪里可以找到列出调用哪些函数的 API 文档?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个好问题,我暂时没有回答它,看看是否有人知道我不知道的事情。
但不幸的是,我想您会发现不可能接收到与此事件对应的通知消息。壁纸幻灯片实际上不会更改系统主题或任何系统设置,因此不会发送
WM_SETTINGCHANGE
消息。它被设计为在后台发生,不需要通知任何应用程序。如果用户选择了“幻灯片”选项,则可以合理地假设他们期望背景会定期更改,无需交互或通知。简而言之,至少在 99% 的情况下,您的应用程序不应因幻灯片选项引起的壁纸更改而做出任何不同的响应。我能想到的最好的办法是确定他们指定的壁纸应该更改的时间间隔,然后让您的应用程序在该时间过去后做出相应的响应。本质上,您必须创建并响应您自己的通知。
强烈不鼓励轮询注册表。这不仅完全没有记录,因此可能会在未来的 Windows 版本(甚至 Windows 更新!)中受到破坏,而且它也不是一个可靠的指标。如果有任何替代方案(包括完全省略功能),这就是我会采取的路径。
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.
实际上我找到了解决该问题的方法。实际上有一个注册表通知机制,因此当指定的键/值更改时可以引发事件。
HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper
是键。当幻灯片更改壁纸时,这不会改变,但该位置的文件确实会改变。通过监视文件的更改,您实际上可以收到此更改的通知。顺便说一句,我正在编码的应用程序的全部要点都依赖于这一点,因此省略它不是一个选择:)。
不过,谢谢你的回复——让我的良心安息,因为我不得不经历如此迂回的做事方式。
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.
我有一个更好的想法,不久前我编写了一个小程序,可以自动更改登录屏幕上的背景,并希望能够自动检测背景上的壁纸并在窗口更改背景时设置相同的壁纸来改进这一点。因此,我开始调查并发现:
因此,算法如下:
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: