Skip to: Site menu | Main content

Login

Name: 
Password:
Remember me?
Register

Setting the Desktop Background Image

written by Mark Rowlinson - Last updated Mar 2006

The following API declare is needed:

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 
 

The following constants are needed:

 
Public Const SPIF_UPDATEINIFILE = &H1 
Public Const SPI_SETDESKWALLPAPER = 20 
Public Const SPIF_SENDWININICHANGE = &H2 

The following function will then set the desktop background when passed the filename of the BITMAP to use:

 
Sub SetBackDrop(strFileName As String) 
    Dim lngR As Long 
     'could check the value of lngR to see if it was sucessful
    lngR = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, strFileName, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE) 
End Sub