Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i am using c# (2003) on win2k and xp as administrator. the following code successfully changes the wallpaper. i am wondering why i have to set the wallpaper to "(None)" first? if i do not, it will not change. if i do, it will change. in either case, SystemParametersInfo returns no error. in my experience, when i have to include a seemingly unnecessary extra line of code to do something, it usually means that i did something wrong earlier. can anyone spot my error?

 

using System;

using System.Windows.Forms;

using System.Runtime.InteropServices;

 

namespace Post

{

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.Button button1;

 

private const int SPI_SETDESKWALLPAPER = 20;

private const int SPIF_UPDATEINIFILE = 0x1;

private const int SPIF_SENDWININICHANGE = 0x2;

 

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]

public static extern int SystemParametersInfo(int uAction , int uParam , string lpvParam , int fuWinIni);

 

public Form1()

{

InitializeComponent();

}

 

#region Windows Form Designer generated code ... (omitted)

[sTAThread]

static void Main()

{

Application.Run(new Form1());

}

 

private void button1_Click(object sender, System.EventArgs e)

{

// Why do I have to set it to none first to make it work???

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "(None)", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, @"C:\WINNT\Soap Bubbles.bmp", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );

}

}

}

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...