A screen saver is really just a Windows program. Screen savers can be divided into two types: full screen and effects. The first type has a bsNone border style, the form is usaully (not always, though) has a black background it’s maximized. They always have the fsStayOnTop form style. The second type is harder to create because they don’t really have a visible form. They perform graphical effects on the screen. These are tougher because there’s a lot more code to write:)
Because screen savers are Windows applications they can freely access Ini files or the system Registry. They perform all the tasks a program can perform.
The screen saver has a .scr extension. You set this (Delphi 4+) in the project’s options or using the {$e ’scr’} directive. No file type conversions are needed.
Windows controls the screen saver using parameters:
- /c - The screen saver is started. Sometimes this parameter will be sent with additional options. The format is: /c:xxxx, where x is a decimal number.
- /p - The screen saver is being installed or the Screen Saver page has been chosen.
- /s -
- No command line options - The screen saver setup should execute.
This example shows how to create a screen saver based on a maximized form with a black (usually) background. At design time set the WindowState property to wsNormal else there may be problems maximizing it programmatically. Set the form’s BorderStyle property to bsNone. Now in the OnCreate event insert this code:
...
WindowState := wsMaximized; { You can't maximize it properly earlier }
...
Don’t forget to include a TTimer component (or something more precise if you want) to control the screen saver’s animation.
You may want to include a “Low CPU Usage” option that won’t take too much of the processor’s precious
time. When this option would be set the screen saver would perform less calculations or at least the TTimer component’s interval property would be multiplied by 2 or 4. You can also do this by lowering the current thread’s and process’es priority level. This option is very useful for users that use screen savers but often have programs running in the background and don’t like the screen saver taking 100% of the CPU’s time. Not everybody has got a Pentium IV or an Athlon system…
Tags: border style, cpu usage, decimal number, delphi 4, design time, graphical effects, ini files, programmatically, scr extension, screen saver setup, screen savers, system registry, type conversions, usage option, windows controls, windows program, xxxx
Merlin’s Delphi Forge
Leave a comment