如何编写Windows应用程序来更改桌面壁纸?

我想编写一个小的Windows应用程序,根据从Web服务检索的照片更改桌面墙纸? 我应该怎么做呢? 哪种语言/技术是最快的代码?

这里还有C#和VB中的示例代码。 除了调用SystemParametersInfo之外,它还为tile和style设置了注册表项。

在网上找到这个(vb)代码:

Private Const SPI_SETDESKWALLPAPER As Integer = &H14 Private Const SPIF_UPDATEINIFILE As Integer = &H1 Private Const SPIF_SENDWININICHANGE As Integer = &H2 Private Declare Auto Function SystemParametersInfo Lib "user32.dll" (ByVal uAction As Integer,_ ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer ' change this to whatever filename you want to use' Const WallpaperFile As String = "MovieCollectionImage.bmp" ''' <summary> ''' Sets the background of your Windows desktop. The image will be saved in MyPictures_ and the background wallpaper updated. ''' </summary> ''' <param name="img">The image to be set as the background.</param> ''' <remarks></remarks> Friend Sub SetWallpaper(ByVal img As Image) Dim imageLocation As String imageLocation = My.Computer.FileSystem.CombinePath_ (My.Computer.FileSystem.SpecialDirectories.MyPictures, WallpaperFile) Try img.Save(imageLocation, System.Drawing.Imaging.ImageFormat.Bmp) SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imageLocation,_ SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE) Catch Ex As Exception MsgBox("There was an error setting the wallpaper: " & Ex.Message) End Try End Sub 

被调用如:

 SetWallpaper (Me.PictureBox1.Image)