Set desktop wallpaper in VB6 and VB.net

Source: Internet
Author: User

Set wallpaper in VB6

Private 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 <br/> const spi_set1_wallpaper = 20 <br/> const spif_sendwininichange = & H2 <br/> const spif_updateinifile = & H1 <br/> private sub command1_click () <br/> Re = systemparametersinfo (spi_set1_wallpaper, 0, "C:/test. BMP ", 0) <br/> end sub <br/>

Set wallpaper in VB. NET 2003

Private const spi_set1_wallpaper as integer = & H14 <br/> private const spif_updateinifile as integer = & H1 <br/> private const spif_sendwininichange as integer = & H2 <br/> private declare auto Function systemparametersinfo lib "user32.dll" (_ <br/> byval uaction as integer, byval uparam as integer, _ <br/> byval lpvparam as string, byval fuwinini as integer) as integer <br/> 'set wallpaper <br/> private sub button#click (byval sender as system. object, byval e as system. eventargs) handles button1.click <br/> systemparametersinfo (spi_set1_wallpaper, 0, "C:/test. BMP ", 0) <br/> end sub <br/> 'unset <br/> private sub button2_click (byval sender as system. object, byval e as system. eventargs) handles button2.click <br/> systemparametersinfo (spi_set1_wallpaper, 0, "", 0) <br/> end sub

Set the wallpaper in VB. NET 2005:

Private const spi_set1_wallpaper as integer = & H14 <br/> private const spif_updateinifile as integer = & H1 <br/> private const spif_sendwininichange as integer = & H2 <br/> private declare auto Function systemparametersinfo lib "user32.dll" (_ <br/> byval uaction as integer, byval uparam as integer, _ <br/> byval lpvparam as string, byval fuwinini as integer) as integer <br/> ''' <summary> <br/> ''' set wallpaper <br/> ''' </Summary> <br/> private sub setwallpaper () <br/> 'get the files in my image directory. In vb2005, use my. computer to get my image directory <br/> dim imglocation as string = My. computer. filesystem. combinepath (my. computer. filesystem. specialdirectories. mypictures, "myimage.bmp") <br/> try <br/> systemparametersinfo (spi_set1_wallpaper, 0, imglocation or spif_sendwininichange) <br/> catch ex as exception <br/> msgbox ("error occurred during setup:" & Ex. message) <br/> end try <br/> end sub <br/>

Refer:

Systemparametersinfo Function Definition and parameters:

The statement is as follows:
Private 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

The meanings of parameters are as follows:

Parameters: Meaning
Uaction Long: Specifies the parameter to be set. Refer to the uaction constant table.
Uparam Long, refer to the uaction constant table
Lpvparam Any: the integer, long, and data structure called by reference.
Fuwinini This parameter specifies whether to update user-defined parameters when setting system parameters.

 

 

 

Below are some uaction parameters and their usage methods:

Parameters Meaning and usage
6 Set the window size, systemparametersinfo (6, zoom in and out, P, 0), and lpvparam to long
17 Enable screensaver, systemparametersinfo (17, false, P, 1), and uparam is Boolean
13, 24 Changes the horizontal and vertical spacing of desktop icons. uparam is the spacing value (pixel), and lpvparam is the long type.
15 Set the screen saver wait time, systemparametersinfo (15, seconds, P, 1), and lpvparam to long
20 Set the desktop background wallpaper, systemparametersinfo (20, true, image path, 1)
93 Switch the mouse track. If systemparametersinfo (93, numeric value, P, 1) and uparam is false, disable it.
97 Switch CTRL + ALT + DEL window, systemparametersinfo (97, false, A, 0), uparam is Boolean

  

 

 

 

In this example, select an image and obtain the complete path of the image. Then, call the API function to set the image as a wallpaper. The syntax used is systemparametersinfo spi_set1_wallpaper, 0, BMP file, 1.

Systemparametersinfo indicates that you want to set the desktop wallpaper. BMP file is the path of the image to be set.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.