February 28, 1996
Using the Microsoft® Windows® application programming interface (API) SystemParametersInfo function, you can remove or change the default desktop wallpaper from within your Microsoft Visual Basic® 4.0 application.
In a Microsoft® Visual Basic® application, the Microsoft Windows® application programming interface (API) SystemParametersInfo function can be used to set many different system-wide parameters. One of these parameters is the desktop wallpaper. Normally, a user would select a new desktop wallpaper by using Control Panel.
As shown in the example program below, the SystemParametersInfo function can be called with the SPI_SETDESKWALLPAPER value and the name of the wallpaper you want to select. The Windows 95 operating system will then make this the new default wallpaper.
The SPIF_SENDWININICHANGE value tells Windows 95 that it should notify all top-level windows of the new change to the system-wide parameters.
This program shows how to remove and select a new desktop wallpaper from within a Visual Basic application.
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 SPIF_UPDATEINIFILE = &H1
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_SENDWININICHANGE = &H2
Private Sub Command1_Click()
Dim X As Long
X = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, "(None)",
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
MsgBox "Wallpaper was removed"
End Sub
Private Sub Command2_Click()
Dim FileName As String
Dim X As Long
FileName = "c:\windows\pinstripe.bmp"
X = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, FileName,
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
MsgBox "Wallpaper was changed"
End Sub
Run the example program by pressing F5. To remove the wallpaper, click the "Remove Wallpaper" command button. Windows 95 displays a black background with no graphics whatsoever. Click the "Change Wallpaper" command button to change the wallpaper to the PINSTRIPE.BMP image.
"Desktop Window." (MSDN Library, Platform, SDK, and DDK Documentation)
Knowledge Base Q97142. "How to Use SystemParametersInfo API for Control Panel Settings."
"SystemParametersInfo QuickInfo Overview Group." (MSDN Library, Platform, SDK, and DDK Documentation)