• 0

[.NET] Detect Wallpaper Change


Question

Alright, so the idea spawned from this post, and it's just a small project I felt like working on...

The idea is to dynamically edit any wallpaper you choose to display in order to colorize the Vista taskbar when it is translucent. It's a pretty cool technique, but it would suck to have to edit every image you want to use as your wallpaper, especially if you like to change your wallpaper quite often. This small freeware program I am going to write will take care of all that, as well as create a temporary image so that your original is not tarnished in any way.

The first task at hand is to determine how to detect when the desktop wallpaper is changed. I've written several programs here and there in Java and C#, but none that really dealt with monitoring a change in the system like this.

So, does anybody have any pointers, specifically for use with .NET? I searched Google and The Code Project for some tips, but I couldn't really phrase the search well enough to get what I needed. Or maybe they're just not out there :laugh:

Off the top of my head, with no investigation whatsoever (it's 2AM here and I'm exhausted), I'm thinking to monitor the registry value that points to the wallpaper image, but once again I haven't investigated yet and I don't know if that's really the best way to do it.

Once I figure out how to do this, I should be fine.

Thanks! :)

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

When Windows changes/sets wallpaper, it calls SystemParametersInfo() function, which sends WM_SETTINGCHANGE message.

So you could override your Form's WndProc():

		// required constants.
		public const int SPI_SETDESKWALLPAPER = 20;
		public const int WM_SETTINGCHANGE = 0x001A;

		// let's override WndProc...
		protected override void WndProc(ref System.Windows.Forms.Message m)
		{
			// if it's WM_SETTINGCHANGE
			if (m.Msg == WM_SETTINGCHANGE)
			{
				if (m.WParam.ToInt32() == SPI_SETDESKWALLPAPER)
				{
					// do something here...
					listBox1.Items.Add("Wallpaper has changed/set!");
					return;
				}
			}
			// else let default WndProc() handle it
			base.WndProc(ref m);
		}

Link to comment
Share on other sites

  • 0
When Windows changes/sets wallpaper, it calls SystemParametersInfo() function, which sends WM_SETTINGCHANGE message.

So you could override your Form's WndProc():

		// required constants.
		public const int SPI_SETDESKWALLPAPER = 20;
		public const int WM_SETTINGCHANGE = 0x001A;

		// let's override WndProc...
		protected override void WndProc(ref System.Windows.Forms.Message m)
		{
			// if it's WM_SETTINGCHANGE
			if (m.Msg == WM_SETTINGCHANGE)
			{
				if (m.WParam.ToInt32() == SPI_SETDESKWALLPAPER)
				{
					// do something here...
					listBox1.Items.Add("Wallpaper has changed/set!");
					return;
				}
			}
			// else let default WndProc() handle it
			base.WndProc(ref m);
		}

:wub: Thank you so much. This will definitely help.

Link to comment
Share on other sites

  • 0

:wub: Thank you so much. This will definitely help.

Sorry to bring this back, but I've got a followup question.

This works great for going preferences > set wallpaper. But if you have slideshow mode on in win7 and the wallpaper changes due to timer or user hitting "show next wallpaper", there is no WndProc message at all (really, not at all).

Anyone know a way to catch THAT case?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.