How to automatically change wallpaper?

xiaoxiao2021-03-06  64

A example of 'SystemParametersInfo function application' ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- '[VB Declaration]' Private Declare Function SystemParametersInfo LIB "User32" Alias ​​"SystemParametersInfoa" (Byval Upram As Long, ByVal Fuwinini As Long) AS Long

'【Description】' Allows and sets the number of Windows system parameters

'[Return value]' long, non-zero means success, zero means failure. Set GetLastError

'[Remarks] "Before calling this function, pay special attention to the definition of the LPVPARAM parameter into the correct data type.

'[Parameter Table]' UAction ------ long, specify the parameters to set. Reference UADION constant table

'Uparam --------- long, refer to the UACTION constant table' LPVPARAM ------- any, Integer, long, and data structures called by reference. For String data, use the SystemParametersInfobyval function. Specific usage reference to uAction constant table

'Fuwinini ------- long, depending on the different parameters and operating systems, the user configuration parameters set with this function is saved in the Win.ini or registry, or saved in these two places. This parameter specifies whether the user setting parameters should be updated when setting the system parameters. Can be zero (disable update), or any of the following constants: 'spif_updateinifile' Updating Win.ini and / or Registry User Profile 'SPIF_SENDWININICHANGE' If SPIF_UPDATEINICHANGE 'is also set, a WM_WININICHANGE message will be sent to all applications. program. Otherwise there is no action. This call tells the application that has changed user configuration settings.

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 LongDim flag As Boolean 'disposed wallpaper Const SPI_SETDESKWALLPAPER = 20' update windows ini file Const spif_updateinifile = & h1const spif_sendWiniChange = & H2

'When the "Add Wallpaper" button is pressed, Private Sub Cmddd_Click ()' pops up the general dialog (Open file) Comopen.Showopen 'If the wallpaper picture is selected to the list box to the list box to ListFile.AddItem Comopen. FILENAMEEND SUB

'When the "exit program" button is pressed, exit Private Sub Cmdexit_Click () unload mend Sub

"The" FLAG is loaded during the "FLAG is the Boolean variable, and whether there is a file in the list box with FLAG = false 'set the interval of automatic replacement wallpaper, the unit is in milliseconds, can change Timer1.Interval = 5000und SUB' When experiencing a certain interval, the timer Timer is awakened, performs the specified task private sub timer1_timer () 'If there is no picture in the list box, no way if listfile.listcount = 0 THEN EXIT SUB' Otherwise, Mark Flag is set to True Else : flag = true end if 'bmpfile is a string variable, storage image path DIM BMPFILE AS STRING' If FLAG reads a file path from the list box and assigns BMPFILE BMPFILE = ListFile.list (Listfile. ListIndex) 'Replace the wallpaper to bmpfile, and modify the INI file systemparametersinfo spi_setdeskwallpaper, 0, bmpfile, spif_updateinifile' If it is already the last picture in the list box, set ListIndex to 0, the first picture if listfile.listIndex = Listfile.listCount - 1 Ten ListFile.listIndex = 0 'Otherwise, ListIndex plus one, pointing the next picture else listfile.listIndex = listfile.listIndex 1 end if end ifend sub

'When the "Immediate Replace" button is pressed, private Sub Cmdnow_Click () DIM BMPFILE AS STRING' If there is no picture in the list box, do not do any action if listfile.listcount = 0 THEN END 'does not change the selected picture to wallpaper BMPFile = Listfile.list (listfile.listindex) SystemParametersInfo SPI_SETDESKWALLPAPER, 0, BMPFILE, SPIF_UPDATEINIFILEEND SUB

转载请注明原文地址:https://www.9cbs.com/read-120027.html

New Post(0)