如何检测因 Windows 7 幻灯片放映而导致的壁纸变化?

发布于 2024-10-30 09:40:17 字数 564 浏览 7 评论 0原文

我正在编写一个程序,需要知道桌面壁纸何时发生变化。经过一番搜索,我找到了部分解决方案: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的心境我的脸 2024-11-06 09:40:18

这是一个好问题,我暂时没有回答它,看看是否有人知道我不知道的事情。

但不幸的是,我想您会发现不可能接收到与此事件对应的通知消息。壁纸幻灯片实际上不会更改系统主题或任何系统设置,因此不会发送 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.

影子的影子 2024-11-06 09:40:18

实际上我找到了解决该问题的方法。实际上有一个注册表通知机制,因此当指定的键/值更改时可以引发事件。
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.

如梦初醒的夏天 2024-11-06 09:40:18

我有一个更好的想法,不久前我编写了一个小程序,可以自动更改登录屏幕上的背景,并希望能够自动检测背景上的壁纸并在窗口更改背景时设置相同的壁纸来改进这一点。因此,我开始调查并发现:

  1. 的一点信息
  2. %USERDIR%\ AppData \ Roaming \ Microsoft \ Windows \ Themes - 来自bg和slideshow.ini的当前转码图像的位置,其中包含有关当前主题%USERDIR%\ AppData \ Local \Microsoft\Windows\Themes - 包含此系统上安装的主题的文件夹

因此,算法如下:

  1. 读取幻灯片.ini 并获取 [幻灯片] 下的值
  2. 读取所有主题文件并比较每个主题文件的 [幻灯片] 值主题,如果它相等 - 我们
  3. 从当前主题的文件中找到当前主题文件,读取 Interval=1800000 的值(在我的例子中是 30 分钟)(顺便说一句,间隔放置在 [幻灯片] 之后,因此可以在同一迭代中完成行)
  4. 从 bg 上的当前图像读取修改时间:%USERDIR%\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper.jpg
  5. 所以,我们有下次更改的时间(当前时间 - 修改时间 + 间隔)并且可以在壁纸更改时执行任何代码(也不要忘记捕获设置更改或禁用更改的情况 - 因为它可能会导致异常,随着改进,我们可以每分钟重新检查此文件或类似的内容)
  6. 如果您尝试编写相同的程序,请不要忘记压缩图像大小,因为它最多需要 256Kb。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文