Interoperation / Office Integration Topics include: COM, P/Invoke (e.g. Win32 API), marshaling, distributed applications, VBA and interacting with office apps

Go Back  Xtreme .NET Talk > .NET > Interoperation / Office Integration > using SystemParametersInfo to change wallpaper in c#


Reply
 
Thread Tools Display Modes
  #1  
Old 10-14-2003, 08:35 PM
pbj pbj is offline
Newcomer
 
Join Date: Oct 2003
Posts: 1
pbj is on a distinguished road
Question using SystemParametersInfo to change wallpaper in c#



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 );
}
}
}
Reply With Quote
  #2  
Old 10-20-2003, 09:08 AM
vsnt vsnt is offline
Newcomer

Preferred language:
vb & C#
 
Join Date: Oct 2003
Posts: 13
vsnt is on a distinguished road
Default

Code looks ok, My initial speculation is that by unsetting it then setting it you are forcing a refresh.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing desktop wallpaper allstar Interoperation / Office Integration 7 09-13-2004 06:18 AM
Getting Name of Wallpaper Voca Directory / File IO / Registry 5 11-26-2003 07:44 AM
Problems setting wallpaper (VB) Meanie General 2 02-21-2003 11:25 AM
Change desktop (jpeg) wallpaper in .net AndyAlexander General 2 01-22-2003 12:33 PM

Advertisement:







Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe