
نوشته شده توسط
amirsajjadi
اگه میشه تغییراتی که روی کدها اعمال کردید رو بنویسید ؟
این کد برنامه ای هست که برای تست تغییر دسکتاپ نوشتم. یه فرم با دو تا Button داره که Button1 برای SetWallPaper و Button2 برای GetWallPaper عمل می کنه.
تذکر:
فایل های wallPaper باید حتماً bmp باشند.
ضمناً این TextEditor فروم یه خورده کدها رو به هم می ریزه. خودتون درستش کنید.
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