Creating Screen Savers for Windows 95 and NT
Using Microsoft Visual C++
and MFC

These pages tell you what you need to know about Windows 95 and NT screen savers, and how to go about creating your own using C++.

The information has been gathered from a range of sources, including Microsoft technical articles, various web sites, and my own experiences.

As an example, I provide the source code for my "Plasma" screen saver. You can download the screen saver here (88K), or download the source code  and project files here (87K).

Mindcaster's  Wonderful Plasma Screen Saver --> Plasma screen image


This isn't what I thought! I want to go home

Tell me about screen saver functions


Contents

Background Information

Constructing Your Screen Saver

Screen Saver Files Creating a Cut-Down MFC Framework
Screen Saver Descriptions The Screen Saver Window Class
Executing Screen Savers The Preview Window Class
Terminating Screen Savers The Configuration Dialog Box
Preventing Multiple Screen Saver Executions Application Initialisation
Screen Saver Passwords Putting It Together
Preventing Alt-Tab and Ctrl-Alt-Del
Disabling the Mouse Cursor PLASMA's CDib Class
Modifying the Desktop PLASMA's Rendering Code
Using The Registry
The Full-Screen Window
The Preview Window
The Configuration Dialog Box
The Password Change DIalog Box
The Request Password Dialog Box
Using MFC as the Screen Saver Framework
Microsoft's SCRNSAVE Library


SCREEN SAVER FILES

You have probably noticed that screen saver files all use the ".scr" extension. This is how they are recognised as screen savers. However, there is nothing special about the ".scr" format : they are just ordinary executable files, but using ".scr" instead of the usual ".exe" extension.

When you use Control Panel to display the available screen savers, all the ".scr" files found in the installation directory and the "System" or "System32" sub-directory are listed.

The installation directory is where Windows is installed. It is usually called "C:\Windows" or "C:\Winnt". Most screen saver files exist in the system sub-directory, which is "System" for 95, and "System32" for NT.


SCREEN SAVER DESCRIPTIONS

How does the Control Panel decide what the screen saver description should be?

If a screen saver file has a long file name, Control Panel will use the file name as the description. A long file name is one that is longer than 8 characters (not counting the extension), or contains special characters (such as commas or spaces).

If a screen saver file does not have a long file name, Windows NT (but not Windows 95) looks for string 1 in the file’s string table, and if found, uses that as the description. If not found, Control Panel just uses the file name.

Windows 95 always uses the filename as the description. It does not search for string table entries.

String tables can be created as resources when using Visual C++.

Old 16-bit screen savers used to get the description from the module name as defined in the ".DEF" file (as long as the name was prefixed with "SCRNSAVE:"). This does not apply when creating 32-bit screen savers.

My advice is to give your screen saver file a sensible long file name, which will end up as the description. Don’t bother with string table entries. The string table process was really to get around only being able to use short file names in earlier versions of Windows. Using a long file name means that your screen saver will always have the same description in Windows 95 and NT.


EXECUTING SCREEN SAVERS

A screen saver file gets executed for three different purposes :

Windows uses command line parameters to let the screen saver know which of these it should do.

/s Run as a full-screen screen saver
/c: Display configuration dialog box
/p Run as a preview window
/a Display password change dialog box (Windows 95 only)

"" is a string containing an integer value representing the handle of the parent window.

If there are no command line parameters, it is a request to display the configuration dialog box.

The password change request only applies to Windows 95. Windows NT, manages screen saver passwords on its own, without having to involve the screen saver programs. Screen saver passwords are described in more detail later on.

There are four ways a screen saver gets started in full-screen mode :

There are two ways a screen saver gets requested to display the configuration dialog box :

The screen saver is requested to run as a preview window whenever the "Screen Saver" tab is displayed in the Control Panel "Display Properties" window, and the screen saver is the currently selected one. The preview window gets displayed in the screen area of the small monitor, and is a handle to the window covering that area.

The screen saver is asked to display the password change dialog box when the Control Panel "Change" button is clicked, to request changing the screen saver password. This button is only present with Windows 95, because Windows NT handles screen saver passwords differently.

Other pages (to follow) explain how your screen saver should handle all these cases.


TERMINATING SCREEN SAVERS

A screen saver needs to terminate when user input (mouse or keyboard) is detected. Your screen saver needs to detect when the mouse is moved, a mouse button is pressed, or a key is pressed. Once detected, the screen saver should terminate (by sending itself a WM_CLOSE message).

Some tolerance should be built into detecting mouse movement. If the screen saver has been started manually, the mouse may still be moving slightly after the screen saver gets going. Also, once going, the mouse may fluctuate very slightly, even if not being touched.

There are a couple of techniques that can be used. The one I favour is to note the position of the cursor when the screen saver starts, and only to terminate if the mouse moves more than 3 or 4 pixels. The other technique is simply to ignore the first few mouse move events.

(Of course, if you want to create "interactive" screen savers then you can actually act on the various types of input, instead of just terminating.)


Next | Home

1