开发者

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

开发者 https://www.devze.com 2022-12-15 10:52 出处:网络
I have figured out how to change the desktop wallpaper (there are dozens of examples on the Internet.)

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


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消