• 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
https://www.neowin.net/forum/topic/567779-net-detect-wallpaper-change/
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("Wallpaperchanged/set!");
					return;
				}
			}
			// else let default WndProc() handle it
			base.WndProc(ref m);
		}

  • 0
  Wilhelmus said:
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("Wallpaperchanged/set!");
					return;
				}
			}
			// else let default WndProc() handle it
			base.WndProc(ref m);
		}

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

  • 0
  On 17/06/2007 at 13:38, gigapixels said:

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

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

    • No registered users viewing this page.
  • Posts

    • Not in Syracuse, NY. They're about to break ground! https://www.syracuse.com/micro...on-and-other-tech-jobs.html
    • Here in Finland we have lots of rural areas with narrow roads, one of the highest taxes in the world (cars are taxed way above EU standards) and fuel is quite expensive. Yet we educate our drivers to drive responsibly and safely in all areas, and our people respect each others rights and freedom to move around safely. Which is why we have even small children under 10 years old walking and cycling alone to schools in the streets, even in big cities. Safety is about being responsible and about respecting others. And I would hate to see AI (or anyone else) destroy our way of life. There are an always will be always outliers, and accidents happen, and machines break. I dont't want to see people relying on AI to do things like driving for them. I want people to think and react to the world around them themselves, and being responsible instead of them browsing TikTok or whatever instead of looking out the window, and then saying that "It wasn't me, it was the car". Already people walk around town with their eyes glued to a screen – I don't want people driving around the same way.
    • And I should hope none will. I don't want to walk ouside to have some randome AI drive over me and mine. Not that I want a person to do it either but I want there to be an actual person who takes responsibility of their actions instead of relinquishing control to a machine. In some highways I can accept self-driving, but even then there should be some kind of dead man switch etc. that actually monitors the drivers status.
    • No thank you. I want to drive myself, and not just because I don't trust a machine or whatever – I like driving, and I like doing it with a manual car without lane guidance and all other "driver assists". I wven rarely use cruise control. I went through and paid for to have a license to that allows me to do it, and do it responsibly instead of relinquishing control to a machine. I currently drive a van for work in a city, something like 200 km/day. If we everything is automated and computers decide everything for us, the dumber people will get since they don't have to bother thinking for themselves nor do they have to take responsibility for themselves since "it wasn't me, it was the machine" will be their future defence for everything. Soon, Neowin's writers will be out of a job because AI can do it just fine and it doesn't need pay. Wikipedia – a free service with voluntary writers – just started replacing real people with AI, and had to shut it down (at least for now). Lets let ai AI and those that run it (or rather run them) the keys the the world and watch it burn because no one is able to actually do anything without some AI assistant telling them what to do (driving included). What a world!
    • I’m sure in the last 12 months there’s been more air disasters
  • Recent Achievements

    • One Month Later
      POR2GAL4EVER earned a badge
      One Month Later
    • One Year In
      Orpheus13 earned a badge
      One Year In
    • One Month Later
      Orpheus13 earned a badge
      One Month Later
    • Week One Done
      Orpheus13 earned a badge
      Week One Done
    • Week One Done
      serfegyed earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      536
    2. 2
      ATLien_0
      247
    3. 3
      +FloatingFatMan
      176
    4. 4
      +Edouard
      166
    5. 5
      Xenon
      118
  • Tell a friend

    Love Neowin? Tell a friend!