setting wallpaper style in vb.net


P

Patrick Dugan

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


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
 
Ad

Advertisements

C

Chris Dunaway

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

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

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename,
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

End Sub

Hi Patrick!

I'm not sure if this will help, but in the declaration to the
SetParametersInfo method, the parameters are all UINT which, I
believe, is an unsigned 2 byte integer. In .Net, Integer is 4 bytes.
You might try changing your declaration from Integer to Short and also
on the SPI* declarations too.

Chris
 
R

rowe_newsgroups

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

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

According to pinvoke.net your GetDesktopWindow declaration is wrong.
Try replacing it with "Private Declare Auto Function GetDesktopWindow
Lib "user32.dll" () As IntPtr"

Here's the page:

http://www.pinvoke.net/default.aspx/user32/GetDesktopWindow.html

Thanks,

Seth Rowe
 
Ad

Advertisements

T

ta7534

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


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top