Patrick Dugan
2007-04-07 16:55:38 UTC
The code below is what i have been *trying* to use to set the desktop
wallpaper picture and the Wallpaper style. The picture gets replaced
with the new image each time, but the style never changes.
Whatever it is set to in the "Display Properties > Desktop" is where is
stays and the code below does not seem to effect it. The registry
entries ARE getting changed but it does not actually apply the new
style. I have tried two different registry entries (The other is
currently remmed out) and I have even tried both at the same time. The
style never gets applied. The return code is always true and the
registry entries do get changed.
What am i missing?
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
Private Declare Function GetDesktopWindow Lib "user32" () As Int32
Dim intWindowStyle as integer = 2 ' 0 = centered, 1= tiled, 2 =
stretched
Friend Sub SetWallpaper(ByVal Filename As String)
Dim imageLocation As String
Dim SPI_SETDESKWALLPAPER As Integer = &H14
Dim SPIF_UPDATEINIFILE As Integer = &H1
Dim SPIF_SENDWININICHANGE As Integer = &H2
Dim RegKey2 As RegistryKey
'RegKey2 =
Registry.CurrentUser.OpenSubKey("Software\Microsoft\Internet
Explorer\Desktop\General", True)
RegKey2 = Registry.CurrentUser.OpenSubKey("Control
Panel\Desktop", True)
RegKey2.SetValue("Wallpaper", WallpaperFile)
Select Case intWindowStyle
Case 0 ' Centered
RegKey2.SetValue("TileWallpaper", 0)
RegKey2.SetValue("WallpaperStyle", intWindowStyle)
Case 1 ' Tiled
RegKey2.SetValue("TileWallpaper", 1)
RegKey2.SetValue("WallpaperStyle", intWindowStyle)
Case 2 ' Stretched
RegKey2.SetValue("TileWallpaper", 0)
RegKey2.SetValue("WallpaperStyle", intWindowStyle)
End Select
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename,
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub
wallpaper picture and the Wallpaper style. The picture gets replaced
with the new image each time, but the style never changes.
Whatever it is set to in the "Display Properties > Desktop" is where is
stays and the code below does not seem to effect it. The registry
entries ARE getting changed but it does not actually apply the new
style. I have tried two different registry entries (The other is
currently remmed out) and I have even tried both at the same time. The
style never gets applied. The return code is always true and the
registry entries do get changed.
What am i missing?
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
Private Declare Function GetDesktopWindow Lib "user32" () As Int32
Dim intWindowStyle as integer = 2 ' 0 = centered, 1= tiled, 2 =
stretched
Friend Sub SetWallpaper(ByVal Filename As String)
Dim imageLocation As String
Dim SPI_SETDESKWALLPAPER As Integer = &H14
Dim SPIF_UPDATEINIFILE As Integer = &H1
Dim SPIF_SENDWININICHANGE As Integer = &H2
Dim RegKey2 As RegistryKey
'RegKey2 =
Registry.CurrentUser.OpenSubKey("Software\Microsoft\Internet
Explorer\Desktop\General", True)
RegKey2 = Registry.CurrentUser.OpenSubKey("Control
Panel\Desktop", True)
RegKey2.SetValue("Wallpaper", WallpaperFile)
Select Case intWindowStyle
Case 0 ' Centered
RegKey2.SetValue("TileWallpaper", 0)
RegKey2.SetValue("WallpaperStyle", intWindowStyle)
Case 1 ' Tiled
RegKey2.SetValue("TileWallpaper", 1)
RegKey2.SetValue("WallpaperStyle", intWindowStyle)
Case 2 ' Stretched
RegKey2.SetValue("TileWallpaper", 0)
RegKey2.SetValue("WallpaperStyle", intWindowStyle)
End Select
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename,
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub