Change wallpaper from .net?

  • Thread starter Thread starter Acer Lam
  • Start date Start date
A

Acer Lam

In VB 6.0 I was able to use API calls to change the
Windows Wallpaper. But for some reason I can't get the
API call to work in VB .Net at all. Anyone know of a way
to change the wallpaper programmatically from VB .Net?
It doesn't have to be an API call, so long as it works.

Here's the code I've tried:
Private Declare Function SystemParametersInfo
Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction
As Long, ByVal uParam As Long, ByVal lpvParam As String,
ByVal fuWinIni As Long) As Long
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_UPDATEINIFILE = &H1
Const SPIF_SENDWININICHANGE = &H2

....
Dim FileName As String
Dim X As Long

FileName = "d:\wallpaper.bmp"

X = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&,
FileName, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

Any help would be greatly appreciated. Thanks in advance.

Acer Lam
(e-mail address removed)
 
In VB 6.0 I was able to use API calls to change the
Windows Wallpaper. But for some reason I can't get the
API call to work in VB .Net at all. Anyone know of a way
to change the wallpaper programmatically from VB .Net?
It doesn't have to be an API call, so long as it works.

Here's the code I've tried:
Private Declare Function SystemParametersInfo
Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction
As Long, ByVal uParam As Long, ByVal lpvParam As String,
ByVal fuWinIni As Long) As Long
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_UPDATEINIFILE = &H1
Const SPIF_SENDWININICHANGE = &H2

...
Dim FileName As String
Dim X As Long

FileName = "d:\wallpaper.bmp"

X = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&,
FileName, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

Any help would be greatly appreciated. Thanks in advance.

Acer Lam
(e-mail address removed)

In VB.NET Long's are 64-bit integers, so you'll want to change
all your Long's to Integer. Also, don't alias the function. Declare it
like this:

Private Declare Auto Function SystemParametersInfo Lib "user32" ( _
ByVal uAction As Integer, _
ByVal uParam As Integer, _
ByVal lpvParam As String) As Integer

This is more efficient because when running on NT systems, you will
avoid a lot of unnecessary string conversions (Unicode vs. Ansi).
 
* "Acer Lam said:
In VB 6.0 I was able to use API calls to change the
Windows Wallpaper. But for some reason I can't get the
API call to work in VB .Net at all. Anyone know of a way
to change the wallpaper programmatically from VB .Net?
It doesn't have to be an API call, so long as it works.

Here's the code I've tried:
Private Declare Function SystemParametersInfo
Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction
As Long, ByVal uParam As Long, ByVal lpvParam As String,
ByVal fuWinIni As Long) As Long

Remove the 'Alias...' and declare the function as 'Auto'. Then replace
all 'As Long' with 'As Int32' (or 'UInt32'), 'fuWinIni' should be
declared as 'Boolean', the return value too.
 
Back
Top