Screen Saver Example

This source code is for Borland Delphi (Object Pascal), it should load and compile cleanly in most versions of the IDE. It was written using the Borland IDE, and tested numerous times in production programs of both my own and others. If you use any of this and find a bug, or just want to tell me it was useful, please contact me to tell me about it.
Modified: 01-26-08, bug fix by Stephan van Ingen.

Relevant Links

Screen Saver Example Code

The source code for the screen saver example is a clean example of writing a screen saver in Delphi. It doesn't do much, as a screen saver, but it makes a great example. Every problem you'll run into writing a screen saver is shown and solved: showing the preview window, keeping it on position, ending when the mouse moves, etc. There are a lot of examples out there of screen savers in Delphi, but I couldn't find one that was a clean screen saver without bugs.

Why is it a good example?

The screen saver example code doesn't just show a screen saver and ignore the problems associated with it. I found many examples that showed the easy part of creating a screen saver and ignored the hard or tedious programming tasks. Here is where this example shines over some others:

So what does it do?

Not much. If you're looking for a nifty screen saver, this isn't it. It was built purely for use as an example. No pretty eye candy here, nifty graphic effects, etc. This was coded simply to demonstrate how to overcome some of the common pitfalls when writing a screen saver. I don't expect anyone to build on this code (although it's fine if they do), or use it to create a world class screen saver. I only expect them to refer to it when they are trying to figure out how to keep the preview window in position while the preview dialog is being moved, or how to keep the screen saver from starting multiple instances.

Limitations

This code is designed for Windows NT/2000/XP/2003, the screen saver will not operate properly on Windows9x because of the differing functionality of password protection on Windows9x. At the time I wrote it, Windows9x was being phased out of common usage. I know there is still a lot of it out there, but I didn't think it was worth it to write the extra code to support 9x; too few people would use it to justify the effort.