我想编写一个小型 Windows 应用程序,它根据从 Web 服务检索到的照片更改桌面墙纸?我该怎么办?用哪种语言/技术编写代码最快?
问问题
1580 次
1 回答
1
在网上找到了这个(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)
于 2009-05-17T02:23:15.333 回答