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/

相关文章:

android - 通过WiFi将图像从Android发送/保存到Windows时,数据过多

c# - 使用 WPF 将 Enter 键发送到外部应用程序时出现问题

java - 使用特定的应用程序Java打开mp3文件

java - 桌面应用程序的现代 Java 需求概述

javascript - 将消息从浏览器中运行的 Javascript 发送到 Windows 批处理文件

c++ - 带有 SetDefault() 的 wxButton 不再响应在框架上输入

java - 如何从 Java 应用程序中获取要为文件显示的图标?

vb6 - Windows 壁纸 : not just BMPs?

javascript - 在 JavaScript Windows 8 应用程序中设置桌面壁纸