Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set desktop background color 1

Status
Not open for further replies.
Thanks JurkMonkey but that is for setting the desktop background WALLPAPER, I want to change the desktop background COLOR.

I am already using that API function to change the wallpaper, which works just fine. I've tried saving the Colors\Background registry setting and running that same api function, but the color does not change.

 
What about creating a bitmap of a given colour programmatically, then save it and use that as the background?

Age is a consequence of experience
 
Thanks litton1 but I can't used that.

When I make the change to the registry, if I log off, then log back on the background color is changed. That tells me that there should be a call that I can make to change it immediately.
I don't understand why the call to SystemParametersInfo doesn't update the color.

 

This is an interop call to change the background color. Let us know how it works out for you.

Code:
Here an example, I hope this help you:

using System.Runtime.InteropServices;

...

const int COLOR_DESKTOP = 1;

uint RGB(byte byRed, byte byGreen, byte byBlue) {
  uint res = byBlue;
  res = res<<8;
  res+=byGreen;
  res = res<<8;
  res+=byRed;
  return res;
}

...

[DllImport("user32.dll")]
public static extern bool SetSysColors(int cElements, int[] lpaElements, uint[] lpaRgbValues);

...

int[] aiElements = {COLOR_DESKTOP}; 
uint[] aColors = {RGB(0x00, 0x80, 0x00)}; 
SetSysColors(1, aiElements, aColors);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top