Jump to content



Photo

[.NET] Detect Wallpaper Change


  • Please log in to reply
4 replies to this topic

#1 vetgigapixels

gigapixels

    Neowinian Senior

  • Joined: 08-December 02
  • Location: California, USA
  • OS: Windows 7 64-bit

Posted 17 June 2007 - 09:06

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! :)


#2 Wilhelmus

Wilhelmus

    Neowinian

  • Joined: 19-February 05
  • Location: Finland

Posted 17 June 2007 - 10:31

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);
		}


#3 b0m8er

b0m8er

    Neowinian Senior

  • Joined: 02-May 03
  • Location: U.S. of A.

Posted 17 June 2007 - 11:35

interestimg idea! keep us posted on your progress! I'd use that program!

#4 OP vetgigapixels

gigapixels

    Neowinian Senior

  • Joined: 08-December 02
  • Location: California, USA
  • OS: Windows 7 64-bit

Posted 17 June 2007 - 13:38

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.

#5 ArmedMonkey

ArmedMonkey

    Neowinian

  • Joined: 02-April 05

Posted 04 April 2011 - 15:36

: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?



Click here to login or here to register to remove this ad, it's free!