How does one detect when the wallpaper has changed (Windows XP or greater)?

一曲冷凌霜 提交于 2019-12-10 17:33:53

问题


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.)


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/2014542/how-does-one-detect-when-the-wallpaper-has-changed-windows-xp-or-greater

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