Change Wallpaper with Windows API (1 Viewer)

doulostheou

Registered User.
Local time
Yesterday, 18:22
Joined
Feb 8, 2002
Messages
314
I am just trying to change the wallpaper through code. The intent is to create a database that will randomly display different wallpapers. I know there are plenty of utilities freely available online that do this, but it is always more fun when you do something yourself.

I believe I found the API function that I need to make this happen, but it is not working, and I am led to believe that it would be something I am doing wrong. If someone could review what I have and let me know where I am going wrong, I would appreciate it. When the code runs, x equals 0 and nothing seems to happen...

I am running Windows 98 if that makes a difference, but I wouldn't that is the case.

Code:
Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
    (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long

Public Const SPI_SETDESKWALLPAPER = 20
Public Const SPIF_SENDWININICHANGE = &H2
            
Sub ChangeWallpaper()
    Dim strBitmapImage As String
    Dim x As Long
    
    strBitmapImage = "E:\My Documents\My Pictures\Circles.bmp"
    
    x = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, strBitmapImage, SPIF_SENDWININICHANGE)
    debug.print x
End Sub
 
Last edited:

doulostheou

Registered User.
Local time
Yesterday, 18:22
Joined
Feb 8, 2002
Messages
314
I got errors when I made the most significant change. The example on the websited used Lib "user" instead of Lib "user" Alias "SystemParametersInfoA". I got debug errors because it couldn't find the user library and then the SystemParameters entry point when I changed it. I changed it back and the code ran again, just didn't change the wallpaper.

I made a few other minor adjustments as well, such as adding the SPIF_UPDATEINIFILE = &H1 constant, but it hasn't made a difference.

I noticed something trying to do this that makes me think it may be my computer and not my code. When I right click on a picture in Internet Explorer and Set as Wallpaper, it does not work either. I am going to try running this same code on a different computer.
 

Users who are viewing this thread

Top Bottom