VB怎样更改电脑桌面违景为拉,请写下详细代码。
添加三个命令按钮,1个PictureBox,1个CommonDialog控件
代码如次:
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
''将新的设置写入用户文件中,&H1=1
Private Const SPIF_UPDATEINIFILE = &H1
Dim PicName As String
''打开图片文件
Private Sub Command1_Click()
''创建打开文件对于话框
With CommonDialog1
.Filter = "bmp文件(*.bmp)|*.bmp"
.ShowOpen
''获患上图片文件名称
PicName = .FileName
End With
''预览图片
Picture1.Picture = LoadPicture(PicName)
''判断是否打开文件
If PicName = "" Then Exit Sub
End Sub
''设置墙纸
Private Sub Command2_Click()
Dim SysInfo As Long
''设置指定图片为桌面墙纸
SysInfo = SystemParametersInfo(SPI_SETDESKWALLPAPER, True, PicName, SPIF_UPDATEINIFILE)
''判断设置是否成功
If SysInfo = 0 Then
MousePointer = 0
MsgBox "很抱歉,不能安装此类墙纸"
Else
MsgBox "恭喜你,成功地安装了墙纸"
End If
End Sub
''退出程序
Private Sub Command3_Click()
End
End Sub
Private Sub Picture1_Change()
Me.Width = Picture1.Width
Me.Height = Picture1.Height * 1.2
End Sub