關於C#替換桌面。我一直在網上找。有兩種方式。一種是修改註冊表 一種是調用系統API:
修改註冊表
using Microsoft.Win32; //寫入註冊表時要用到
//設置壁紙
//導航到Policies項
RegistryKey hkml = Registry.CurrentUser;
RegistryKey software = hkml.OpenSubKey( @"Software\Microsoft\Windows\CurrentVersion\Policies\" , true );
//新建立System項
RegistryKey aimdir = software.CreateSubKey( "System" );
aimdir.SetValue( "Wallpaper" , photoURL );//URL是圖片的URL
reKey.SetValue( "TileWallpaper" , "0" );
aimdir.SetValue( "WallpaperStyle" , "2" );
//關閉節點,並保存修改
hkml.Close();
software.Close();
aimdir.Close();
調用系統API
using System.Runtime.InteropServices; //調用WINDOWS API函數時要用到
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern int SystemParametersInfo(
int uAction ,
int uParam ,
string lpvParam ,
int fuWinIni
);
SystemParametersInfo( 20 , 1 , photoURL , 1 );