Search

Help

Home


Adding screen saver settings

How it works Where to from here?

Part 2 of our screen saver tutorial, Helen Bradley adds a setup form so you can customise the settings.

We're going to show you how to add a setup form to our screen saver so you can change the background colour of the screen and the number of pieces of confetti which will be drawn before the screen is cleared and the process restarted. We'll store this information in the control.ini file so that the settings are retained permanently.

To create the setup form, shown in Figure 1, open the project pcusaver.vbp and add a new form using Insert, Form.

Add these controls to the form and set these properties:

Play ScreenCam
tutorial Part 4

Play ScreenCam
tutorial Part 5


Figure 1: The setup form allows you to change the background colour and number of 'pieces of confetti' on the screen.

Object
Name
Property
Setting
Form SetUpForm Caption PCU Screen Saver Setup
BorderStyle 3-Fixed Dialog
MinButton False
MaxButton False
Icon confetti.ico (on this month's
CD-ROM) or another suitable one
Command cmdOK Caption &OK
Default True
Command cmdCancel Caption &Cancel
    Cancel True
Command cmdColorChange Caption Change &Background Color
CommonDialog CommonDialog1    
Text box txtMaxCircles Text 500
TabIndex 0
Label Label1 Caption Maximum pieces of confetti (0-30,000)
Label Label2 Caption Confetti Screen Saver
PictureBox Picture1 AutoSize True
Picture Monitr01.ico from the
/icons/computer collection
Border None

Figure 2: The section name and keyname are written to an INI file by the WritePrivateProfileString API function.
Type the code in code box 1 into this form and save it calling it setupfrm.frm.

Make the changes to the code in last month's form and module listed in code box 2 and save your project.

Select Tools, Options, Project and in the Startup Form list box, select Sub Main and click OK. You can test the new form by selecting Tools, Options and selecting the Advanced tab. Enter /c as the Command Line Argument and click OK. Running the project will now run the setup form. Change the command line argument to /s to test the mainform.

When your program runs correctly, select File, Make EXE File, select your \WINDOWS\SYSTEM directory and name your file pcusaver.scr. Select Options and in the Title box, type SCRNSAVE: PCUSaver and select OK and OK.

You can now select your screensaver by running Control, Desktop in Windows 3.1 or Control Panel, Display in Win 95. Select the screensaver from the list (it's called pcusaver), you'll find that now both the Settings and the Preview (Test) buttons will be fully functional.

Files associated with this tutorial can be found in the \interact\scrnsav\ directory on the CD. How it works

The new form allows you to set the background colour of the form and change the number of circles (pieces of confetti) that are drawn on the screen before it is cleared and the pattern starts again. The choices you make are stored in string variables called userSelection and tempColour and written to the control.ini file by the WritePrivateProfileString API function when the OK button on the setup form is selected.

The first time the WritePrivateProfileString function is called there is no section name or keyname in the control.ini file so the function creates these for you. The second and subsequent times when the section and keynames already exist, the information stored against these keynames will simply be updated. Figure 2 shows the section name and keynames in the relevant part of control.ini after the OK button on the setup form has been selected.

The number of circles is being kept to the range 0-30,000 so that it can be stored in an integer variable. There is a check in the cmdOK_Click event to ensure the number is below 30,000 (if it is higher it is replaced by 30,000) but we have no check for errors such as negative or real numbers. Because of the much larger range of possible screen colour numbers (255 by 255 by 255), a long variable is used to store the screencolour integer.

The procedure main() which is run when the program is first run, reads the number of circles and screen colour information from the control.ini file using the GetPrivateProfileInt API function. If the section name or keyname don't exist in the control.ini file, default values are returned (these are specified as the third argument in the function call). Depending on whether you pressed the Setting or Preview (Test) button, the appropriate form will be displayed.

Where to from here?

This screen saver is simple but it is fully functional and you can use it as a template to write your own screen saver. Start by replacing the code in the Timer1.timer event with your own screen graphics and add or alter the information written and read from the control.ini file to suit your needs.

References and further reading.

  • Teach Yourself Visual Basic 4 for Windows 95, by John Socha and Derva Hall, MIS Press
  • Microsoft Knowledge Base articles
  • Creating screen savers from VB Tips & Tricks May 96,Peter Provost, San Diego, CA.
  • Microsoft Visual Basic 4.0 Developers Workshop, John Clark Craig, Microsoft Press.

Top of page

|What's New | Software | Net Guides | Web Workshop | Net Sites | About PC User |

All text © 1997 Australian Consolidated Press - PC User Magazine