Class To Change Wallpaper In Xp,Vista,Windows 7 From C#.Net
2012-04-01 14:50
495 查看
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.IO; using Microsoft.Win32; using System.Drawing; public sealed class clsWallpaper { const int SPI_SETDESKWALLPAPER = 20; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDWININICHANGE = 0x02; [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); public enum Style : int { Tiled, Centered, Stretched } public static void Set(Uri uri, Style style) { System.IO.Stream s = new System.Net.WebClient().OpenRead(uri.ToString()); System.Drawing.Image img = System.Drawing.Image.FromStream(s); string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp"); img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp); RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); if (style == Style.Stretched) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == Style.Centered) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == Style.Tiled) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); } }
相关文章推荐
- How to change windows wallpaper in C#
- Use C# to get JSON Data from the Web and Map it to .NET Class => Made Easy! 转
- How to change the language of oracle sqlplus from chinese to english in windows(如何将oracle sql plus中的中文变成英文版)
- How to Change the Icon for a File Type in Windows 7 and Vista(转)
- HOW TO: Set a Windows Hook in Visual C# .NET
- Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(1)
- ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(6)
- Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(2)
- Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(3)
- Beginning ASP .NET 2.0 E-Commerce in C# 2005: From Novice to Professional
- Beginning ASP.NET 2.0 in C# 2005: From Novice to Professional (Beginning: from Novice to Professiona
- Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(4)
- Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional, Second Edition
- How to launch Windows applications (Notepad) / Call Batch files from a C#/.NET console application.
- How to Change Password Complexity Requirements in Windows XP
- Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译
- Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(5)
- Beginning ASP.NET E-Commerce in C#: From Novice to Professional
- Beginning ASP.NET 3.5 in VB 2008: From Novice to Professional, Second Edition