Writing Your Own Screen Saver

by Mark Dawson - Independent Developer
Image of Line Break

Writing your own Control Panel Desktop activated screen saver requires only a few simple steps. Some other methods I've seen go to great lengths by writing activation routines in C that register themselves with ScreenSaverProc and WinExec a VB exe, or use custom DLLs. However, you can do everything from within VB much more simply.

  1. In VBís Make EXE dialog, type in "SCRNSAVE:ScreenSaverName". Also, change the EXE filename from .EXE extension to .SCR. Make the saver straight into your Windows directory.

    Windows only scans its home directory when firing up screen savers.

  2. Make a VB project with at least a single maximised background form. This form should have all Control Boxes, Max/Min buttons turned off. Set BorderStyle to 0-None.

    I like to make the background totally black by setting the BackColor to black.

  3. In the formís KeyDown and MouseMove events, insert code to end the app if the event is detected. One quirk is that, for some reason, VB apps detect one MouseMove event the first time the form is shown. To get around this, insert code to discard the first (and ONLY the first) MouseMove event.

  4. In your Form_Load, Sub Main or whatever, insert code to parse the command line for the argument "/C". Windows Control Panel Desktop sends this command line argument to your screen saver when you click on Setup.

    You could put in a nice configuration dialog for your screen saver. Along with an About box claiming credit for your wonderful saver.

  5. For that professional look, you really should also get rid of the unsightly mouse pointer using the ShowCursor API. Don't forget to re-enable it on screen saver de-activation otherwise users will lose their mouse!

  6. You should also further beautify your screen saver by calling the SetWindowPos API (yeah I know, another API call) to make your saverís background form "TopMost" ie. it always remains on top, thereby covering running CLOCK.EXEs and the like.

  7. OPTIONAL: You may also need to make the screen saver's window System Modal (ie when it runs it monopolises all windows processing). If you use multiple timers this is especially the case.

  8. You now have the skeleton of a screen saver. You can now animate cows chewing their cud in 16.7 million colours, playback DOOM deathmatches, or display compromising scanned bitmaps of your boss and all your workmates.

Enjoy!


Written by: Mark Dawson
August 1995

Image of arrow to previous article Image of arrow to next article

[HOME] [TABLE OF CONTENTS] [SEARCH]