Set wallpaper in VB6
Private Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoa" (Byval Upram as ring, Byval Fuwini as long) As long
Const spi_setdeskwallpaper = 20
Const SPIF_SENDWININICHANGE = & H2
Const spif_updateinifile = & h1
Private submmand1_click ()
RE = SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, "C: / Test.BMP", 0)
End Sub
Set wallpaper in VB.NET 2003
Private const spi_setdeskwallpaper as integer = & h14
Private const spif_updateinifile as integer = & h1
Private const spif_sendWiniChange as integer = & h2
Private Declare Auto Function SystemParametersInfo LIB "User32.dll" (_
Byval uaction as integer, byval uparam as integer, _
BYVAL LPVPARAM AS STRING, BYVAL Fuinini As INTEGER AS INTEGER
'Set wallpaper
Private sub button1_click (byvale as system.object, byval e as system.eventargs) Handles Button1.click
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, "c: /test.bmp", 0)
End Sub
'Cancel settings
Private sub Button2_click (byvalgend, byval e as system.eventargs) Handles Button2.click
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, "", 0)
End Sub
Set wallpaper in VB.NET 2005:
Private const spi_setdeskwallpaper as integer = & h14
Private const spif_updateinifile as integer = & h1
Private const spif_sendWiniChange as integer = & h2
Private Declare Auto Function SystemParametersInfo LIB "User32.dll" (_
Byval uaction as integer, byval uparam as integer, _
BYVAL LPVPARAM AS STRING, BYVAL Fuinini As INTEGER AS INTEGER
'' '
'' Set wallpaper
'' summary>
Private sub set guardpaper () gets the file in my picture directory, in the VB2005, use my.computer to get my picture directory.
Dim imglocation as string = my.computer.Filesystem.comBBinePath (My.Computer.Filesystem.SpecialDirectories.mypictures, "MyImage.BMP")
Try
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, IMGLOCATION OR SPIF_SENDWININICHANGE)
Catch exception
Msgbox ("Error in the settings:" & ex.Message)
END TRY
End Sub
reference:
The definition and parameters of the SystemParametersInfo function:
Declare: Private Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoa" (Byval Upram As Long, Byval FUWININI As Long) As long
The significance of each of these parameters is as follows:
Parameters: Meaning uActionLong, specify the parameters to set. Refer to the UAction constant table Uparamlong, refer to the UACTION constant table lpvparamany, the Integer, long, and data structure called calls. FUWININI This parameter specifies whether the user setting parameters should be updated when setting the system parameters.
Below is a part of the uAction parameters, and how they use them:
parameter
Significance and method of use
6
Set the size of the window, SystemParametersInfo (6, magnifying value, p, 0), lpvparam is long
In one
Switch Screenword, SystemParametersInfo (17, False, P, 1), Uparam is Boolean
13,24
Change the level of desktop icon and vertical spacing, upram is a spacing value (pixel), lpvparam is long
15
Set screensaver waiting time, SystemParametersInfo (15, seconds, p, 1), lpvparam is long
20
Set the desktop background wallpaper, SystemParametersInfo (20, True, Image Path, 1)
93
Switch mouse trajectory, SystemParametersInfo (93, Numerical, P, 1), Uparam is closed for False
97
Switch Ctrl Alt DEL window, SystemParametersInfo (97, False, A, 0), Uparam is Boolean
In this example, we select the picture and get the full path to get the picture, and then set this image to wallpaper by calling the API function, using the syntax for use: SystemParametersInfo SPI_SETDESKWALLPAPER, 0, BMPFILE, 1
SystemParametersInfo means that you want to set the desktop wallpaper, BMPFile is the path to the image to be set.