PC Review


Reply
Thread Tools Rate Thread

Change wallpaper from .net?

 
 
Acer Lam
Guest
Posts: n/a
 
      7th Dec 2003
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 Removed)
 
Reply With Quote
 
 
 
 
Tom Shelton
Guest
Posts: n/a
 
      7th Dec 2003
On 2003-12-07, Acer Lam <(E-Mail Removed)> wrote:
> 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 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).

--
Tom Shelton
MVP [Visual Basic]
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Dec 2003
* "Acer Lam" <(E-Mail Removed)> scripsit:
> 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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can't change wallpaper =?Utf-8?B?Qm9iQm9i?= Windows XP Configuration 3 18th Feb 2007 07:19 PM
cannot change wallpaper - please help - thanks Tony Windows XP Customization 1 4th Jul 2004 04:42 AM
Cannot change wallpaper. HELP! John Windows XP Customization 0 8th Dec 2003 10:52 AM
My XP wallpaper won't change Vallis Windows XP New Users 1 23rd Oct 2003 09:47 PM
Can't Change Wallpaper mad amoeba Windows XP Basics 4 27th Aug 2003 04:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:31 AM.