如何检测壁纸何时更改(Windows XP 或更高版本)?

发布于 2024-08-17 04:01:23 字数 87 浏览 11 评论 0原文

我已经弄清楚如何更改桌面壁纸(互联网上有几十个示例。)

仍然让我困惑的一件事:如何检测壁纸何时更改? (比如通过显示控制面板或其他程序更改它。)

I have figured out how to change the desktop wallpaper (there are dozens of examples on the Internet.)

One thing that still eludes me: how do I detect when the wallpaper has changed? (Say via the Display control panel or another program changing it.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

长亭外,古道边 2024-08-24 04:01:23

在.NET 中添加 WM_SETTINGCHANGE、SystemEvents.UserPreferenceChanged 的​​消息处理程序。检查壁纸是否仍然相同。

Add a message handler for WM_SETTINGCHANGE, SystemEvents.UserPreferenceChanged in .NET. Check if the wallpaper is still the same.

永不分离 2024-08-24 04:01:23

下面是 C# 中检索壁纸的示例。您需要添加的只是一些额外的代码来存储最后的壁纸并检查它是否不同。

RegistryKey wallpaper = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop",false);
string wallpapername = wallpaper.GetValue("wallpaper").ToString();          
wallpaper.Close();

如果您使用非 .net 语言编写某些内容,则可以使用 Win32 API RegNotifyChangeKeyValue 函数来检查该值是否已更改:

HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper

Here is an example in C# to retrieve the wallpaper. All you would need to add is some additional code to store the last wallpaper and check to see if it is different.

RegistryKey wallpaper = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop",false);
string wallpapername = wallpaper.GetValue("wallpaper").ToString();          
wallpaper.Close();

If you were writing something in a non .net language you could use the Win32 API RegNotifyChangeKeyValue function to check to see if this value has changed:

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