如何用VB随机改变桌面背景的代码

来源:百度知道 编辑:UC知道 时间:2024/06/05 10:16:32
任意选取一张未知图片来作为桌面背景?

实现这个功能要调用一个API。
然后加载源图到Image控件里面,并保存为BMP图片到硬盘上,再用API设定保存的BMP为桌面背景。

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Private Const SPI_SETDESKWALLPAPER = 20
Dim WithEvents Image1 As Image

Private Sub Form_Load()

Dim aa As String

aa = "C:\8.jpg" '源图片

With Form1
Set Image1 = .Controls.Add("VB.Image", "Image1", Form1)
.Width = 4000
.Height = 4000
End With

With Form1!Image1
.Visible = True
.Height = 4000
.Width = 4000
.Top = 120
.Left = 120
.Picture = LoadPicture(aa) '加载图片
End With

aa = "C: