javad2000
پنج شنبه 05 مهر 1386, 15:35 عصر
سلام
من این کد رو از محیط vb 2005 کپی کردم و اینجا گذاشتم. نگاه کنید چی به سرش اومده:
PublicClass Form1
Inherits System.Windows.Forms.Form
PrivateDeclareFunction SystemParametersInfo Lib"user32"Alias"SystemParametersInfoA" (ByVal uAction AsInteger, ByVal uParam AsInteger, ByVal lpvParam AsString, ByVal fuWinIni AsInteger) AsInteger
PrivateConst SPI_SETDESKWALLPAPER AsShort = 20
PrivateConst SPIF_UPDATEINIFILE AsShort = 1
PublicEnum WallPaperStyle AsInteger
Tiled
Centered
Stretched
EndEnum
Sub SetWallPaper(ByVal FilePath AsString, ByVal UpdateRegistry AsBoolean, ByVal wpStyle As WallPaperStyle)
Dim upd AsShort
If UpdateRegistry Then
upd = SPIF_UPDATEINIFILE
Else
upd = 0
EndIf
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
Try
SelectCase wpStyle
Case WallPaperStyle.Stretched
key.SetValue("WallpaperStyle", "2")
key.SetValue("TileWallpaper", "0")
Case WallPaperStyle.Centered
key.SetValue("WallpaperStyle", "1")
key.SetValue("TileWallpaper", "0")
Case WallPaperStyle.Tiled
key.SetValue("WallpaperStyle", "1")
key.SetValue("TileWallpaper", "1")
EndSelect
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, FilePath, upd)
Catch ex As Exception
'MsgBox(ex.Message)
EndTry
EndSub
Function GetWallPaper() AsString
Try
ReturnMy.Computer.Registry.GetValue _
("HKEY_CURRENT_USER\Control Panel\DeskTop", "WallPaper", "")
Catch ex As Exception
Return""
'MsgBox(ex.Message)
EndTry
EndFunction
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim A AsNew OpenFileDialog
A.ShowDialog()
Me.SetWallPaper(A.FileName, True, WallPaperStyle.Stretched)
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(GetWallPaper)
EndSub
EndClass
من این کد رو از محیط vb 2005 کپی کردم و اینجا گذاشتم. نگاه کنید چی به سرش اومده:
PublicClass Form1
Inherits System.Windows.Forms.Form
PrivateDeclareFunction SystemParametersInfo Lib"user32"Alias"SystemParametersInfoA" (ByVal uAction AsInteger, ByVal uParam AsInteger, ByVal lpvParam AsString, ByVal fuWinIni AsInteger) AsInteger
PrivateConst SPI_SETDESKWALLPAPER AsShort = 20
PrivateConst SPIF_UPDATEINIFILE AsShort = 1
PublicEnum WallPaperStyle AsInteger
Tiled
Centered
Stretched
EndEnum
Sub SetWallPaper(ByVal FilePath AsString, ByVal UpdateRegistry AsBoolean, ByVal wpStyle As WallPaperStyle)
Dim upd AsShort
If UpdateRegistry Then
upd = SPIF_UPDATEINIFILE
Else
upd = 0
EndIf
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
Try
SelectCase wpStyle
Case WallPaperStyle.Stretched
key.SetValue("WallpaperStyle", "2")
key.SetValue("TileWallpaper", "0")
Case WallPaperStyle.Centered
key.SetValue("WallpaperStyle", "1")
key.SetValue("TileWallpaper", "0")
Case WallPaperStyle.Tiled
key.SetValue("WallpaperStyle", "1")
key.SetValue("TileWallpaper", "1")
EndSelect
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, FilePath, upd)
Catch ex As Exception
'MsgBox(ex.Message)
EndTry
EndSub
Function GetWallPaper() AsString
Try
ReturnMy.Computer.Registry.GetValue _
("HKEY_CURRENT_USER\Control Panel\DeskTop", "WallPaper", "")
Catch ex As Exception
Return""
'MsgBox(ex.Message)
EndTry
EndFunction
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim A AsNew OpenFileDialog
A.ShowDialog()
Me.SetWallPaper(A.FileName, True, WallPaperStyle.Stretched)
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(GetWallPaper)
EndSub
EndClass