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

标签 windows desktop desktop-wallpaper

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

最佳答案

在网上找到这个 (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)

关于windows - 如何编写Windows应用程序来更改桌面墙纸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/873756/

相关文章:

c - 如何在 TWAIN 中最大化扫描区域?

c++ - SystemParametersInfo 将壁纸设置为完全黑色(使用 SPI_SETDESKWALLPAPER)

windows - "For"和 "usebackq"不使用反引号

windows - ADSI 是否可以用于为首次登录需要更改的 Windows 帐户设置密码

delphi - 如何在 Delphi 7 应用程序中支持自定义桌面 DPI 设置?

java - 捕捉桌面图像

java - 将以前使用的字符串导入到新方法中

c++ - 独立于桌面环境或窗口管理器以编程方式更改 Linux 中的墙纸

c++ - 以编程方式在 Linux 上更改墙纸

python - 是否可以直接在ODBC连接字符串中指定驱动程序dll?