How to create an automatic Wallpaper Changer with Visual Basic 6.0






1.94/5 (8 votes)
How to create an automatic Wallpaper Changer with Visual Basic 6.0
Download chwallpaper_src.zip - 159.46 KB
Designing apps in Visual basic is pretty straightforward.
Click on the desired component (control) , located at the left toolbar
of visual basic and draw it at an appropiate locaton on the form.
Componments on the form align to rectangular grids giving
your apps a symmetric look.
This app uses the following components:
- command buttons
- radio buttons
- check boxes
- horizontal scroll bars
- frames
- image controls
- list box
- timer
- labels
Altering the wallpaper change mode
Selection of how the app will change desktop wallpapers is
done here. One can either let the app automatically change
wallpapers or one can manually do so by clicking the
'set as wallpaper' button.
Private Sub optMode_Click(Index As Integer) Select Case Index Case 0: optMode(0).Value = True Case 1: optMode(1).Value = True End Select End Sub
If optMode(0).Value = True Then '*********************** If optSeq(0).Value = True Then cnt = cnt + 1 Frame5.Caption = " Wallpapers ( " & MaxWallpaperFiles & " files ) " & MaxWallpaperFiles - cnt & " to go " 'CurrentWallpaperFile = DoneWallpaperFiles(cnt) CurrentWallpaperFile = Int(MaxWallpaperFiles * Rnd) List1.ListIndex = CurrentWallpaperFile 'If (DoneFileCount > MaxWallpaperFiles) Then If (cnt > MaxWallpaperFiles - 1) Then cnt = 0 ' DoneFileCount = 0 GenerateRandomFile End If End If
Setting the wallpaper change sequence
The sequence of the wallpapers can be randomily done or
sequenced in a foward non-random direction.
The app generates a series of random numbers, stores them
in an array. This is done to assure that numbers arent
repeated as often occurs when using the random function.
Private Sub optSeq_Click(Index As Integer) Select Case Index Case 0: optSeq(0).Value = True optSeq(1).Value = False autoMode = True Case 1: optSeq(1).Value = True optSeq(0).Value = False autoMode = False End Select End Sub
If optSeq(1).Value = True Then List1.ListIndex = CurrentWallpaperFile FileName1 = DriveLetter & WallpaperFile(CurrentWallpaperFile).Path & WallpaperFile(CurrentWallpaperFile).Name Image1.Picture = LoadPicture(FileName1) If (CurrentWallpaperFile > MaxWallpaperFiles - 1) Then CurrentWallpaperFile = 0 Frame5.Caption = " Wallpapers ( " & MaxWallpaperFiles & " files ) " & (MaxWallpaperFiles - 1) - CurrentWallpaperFile & " to go " Else 'DoneFileCount = DoneFileCount + 1 'CurrentWallpaperFile = DoneWallpaperFiles(DoneFileCount) End If
Adjusting the wallpaper change time
The default time and max time is set to 30 seconds but can be
reduced down to 2 seconds using the scrollbar.
Private Sub HScroll1_Change() Timer1.Interval = HScroll1.Value Label10.Caption = " " & Timer1.Interval / 1000 & " seconds" WallpaperChangeInterval = HScroll1.Value End Sub
The Program's loop
< alt="Screenshot - wall06_timer.jpg" src="wallpaperchanger/wall06_timer.jpg" />
The core of this app has been placed in Timer1
to make things as simple as can be.
Private Sub Timer1_Timer() '******************** '** ** '******************** On Error Resume Next TimerStart = Timer 'Delay = ((TimeDelay / 1000) - (TimerElap - TimerStart)) * 1000 Delay = TimeDelay - Int(((TimerElap - TimerStart)) * 1000) '*********************** If optMode(0).Value = True Then '*********************** If optSeq(0).Value = True Then cnt = cnt + 1 Frame5.Caption = " Wallpapers ( " & MaxWallpaperFiles & " files ) " & MaxWallpaperFiles - cnt & " to go " 'CurrentWallpaperFile = DoneWallpaperFiles(cnt) CurrentWallpaperFile = Int(MaxWallpaperFiles * Rnd) List1.ListIndex = CurrentWallpaperFile 'If (DoneFileCount > MaxWallpaperFiles) Then If (cnt > MaxWallpaperFiles - 1) Then cnt = 0 ' DoneFileCount = 0 GenerateRandomFile End If End If '*********************** If optSeq(1).Value = True Then List1.ListIndex = CurrentWallpaperFile FileName1 = DriveLetter & WallpaperFile(CurrentWallpaperFile).Path & WallpaperFile(CurrentWallpaperFile).Name Image1.Picture = LoadPicture(FileName1) If (CurrentWallpaperFile > MaxWallpaperFiles - 1) Then CurrentWallpaperFile = 0 Frame5.Caption = " Wallpapers ( " & MaxWallpaperFiles & " files ) " & (MaxWallpaperFiles - 1) - CurrentWallpaperFile & " to go " Else 'DoneFileCount = DoneFileCount + 1 'CurrentWallpaperFile = DoneWallpaperFiles(DoneFileCount) End If ChangeWallpaper CurrentWallpaperFile = CurrentWallpaperFile + 1 If (CurrentWallpaperFile > MaxWallpaperFiles - 1) Then CurrentWallpaperFile = 0 'DoneFileCount = DoneFileCount + 1 'MsgBox DoneFileCount & ". " & DoneWallpaperFiles(DoneFileCount) & " opps" End If End Sub
when all said and done
(when the code is run)
Browsing for wallpapers and
selecting wallpaper folders.
Obviously this app would be useless without this feature. Browsing for
folders containing wallpapers is pretty straightforward. Select the
folder containing the 'bmp files and click the ' ok ' button.
The app will list all bmp files found in the directory, in the list box
located to the lower left section of the form.
Selecting the files is done by clicking the file in question,
a preview of the .bmp file will be rendered in the wapaper preview.
Clicking the ' set as wallpaper ' will set it as wallpaper or
one can click the ' automatic ' radio button to have the app
automatically set the wallpapers.
Download Source code : Download chWallpaper_src.zip - 198.03 KB