Click here to Skip to main content
15,868,087 members
Articles / Programming Languages / Visual Basic 6

How to create an automatic Wallpaper Changer with Visual Basic 6.0

Rate me:
Please Sign up or sign in to vote.
1.94/5 (8 votes)
28 Jun 2010CPOL2 min read 45.4K   2.2K   22   5
How to create an automatic Wallpaper Changer with Visual Basic 6.0

Download chwallpaper_src.zip - 159.46 KB

Image 1

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

Screenshot - wall03_change_mode.jpg

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
Screenshot - wall04_change_sequence.jpg

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

Screenshot - wall05_change_delay.jpg

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="/KB/vb/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)

Image 5


Browsing for wallpapers and
selecting wallpaper folders.

03.jpg

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Sweden Sweden
About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

Comments and Discussions

 
Questioncompliment Pin
plikukaku9-Dec-12 6:15
plikukaku9-Dec-12 6:15 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey16-Feb-12 19:59
professionalManoj Kumar Choubey16-Feb-12 19:59 
QuestionPeople still use this??? Pin
Eli Nurman10-Jun-10 6:33
Eli Nurman10-Jun-10 6:33 
GeneralMy vote of 1 Pin
Member 15069667-Jun-10 6:49
Member 15069667-Jun-10 6:49 
terrible
Generalhey you people, post comments Pin
Software_Developer5-Dec-07 3:40
Software_Developer5-Dec-07 3:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.