About Screen Savers

The Desktop application in Windows Control Panel lets users select from a list of screen savers, specify how much time should elapse before the screen saver is started, configure screen savers, and preview screen savers. Screen savers are loaded automatically when Windows starts or when a user activates the screen saver feature by using Control Panel.

Once a screen saver is chosen, Windows monitors keystrokes and mouse movements, starting the screen saver after a period of inactivity. However, Windows does not start the screen saver if any of the following conditions exist:

  • The active application is not a Windows-based application.

  • A computer-based training (CBT) window is present.

  • The active application receives the WM_SYSCOMMAND message with wParam set to the SC_SCREENSAVE value, but does not pass the message to the DefWindowProc function.

Screen savers contain specific exported functions, resource definitions, and variable declarations. The static-link library SCRNSAVE.LIB contains the main function and other startup code required for a screen saver. When a screen saver starts, the startup code in SCRNSAVE.LIB creates a full-screen window. The window class for this window is declared as follows.

WNDCLASS cls;

cls.hCursor = NULL;

cls.hIcon = LoadIcon(hInst, MAKEINTATOM(ID_APP));

cls.lpszMenuName = NULL;

cls.lpszClassName = "WindowsScreenSaverClass";

cls.hbrBackground = GetStockObject(BLACK_BRUSH);

cls.hInstance = hInst;

cls.style = CS_VREDRAW | CS_HREDRAW |

CS_SAVEBITS | CS_DBLCLKS;

cls.lpfnWndProc = (WNDPROC) ScreenSaverProc;

cls.cbWndExtra = 0;

cls.cbClsExtra = 0;

To create a screen saver, most developers create a source-code module containing three required functions and link them with SCRNSAVE.LIB. A screen saver module is responsible only for configuring itself and for providing visual effects.

One of the three required functions in a screen saver module is ScreenSaverProc. This function processes specific messages and passes any unprocessed messages back to SCRNSAVE.LIB. Following are some of the typical messages processed by ScreenSaverProc.

Message
Meaning
WM_CREATE
Retrieve any initialization data from the file REGEDIT.INI. Set a window timer for the screen saver window. Perform any other required initialization.
WM_ERASEBKGND
Erase the screen saver window and prepare for subsequent drawing operations.
WM_TIMER
Perform drawing operations.
WM_DESTROY
Destroy the timer(s) created when the application processed the WM_CREATE message. Perform any additional required cleanup.

ScreenSaverProc passes unprocessed messages to SCRNSAVE.LIB by calling the DefScreenSaverProc function. The following table describes how this function processes various messages.

Message
Action
WM_SETCURSOR
Sets the cursor to the null cursor, removing it from the screen.
WM_PAINT
Paints the screen background.
WM_LBUTTONDOWN
Terminates the screen saver.
WM_MBUTTONDOWN
Terminates the screen saver.
WM_RBUTTONDOWN
Terminates the screen saver.
WM_KEYDOWN
Terminates the screen saver.
WM_MOUSEMOVE
Terminates the screen saver.
WM_ACTIVATE
If wParam is FALSE, terminates the screen saver.

The second required function in a screen saver module is ScreenSaverConfigureDialog. This function displays a dialog box that enables the user to configure the screen saver. (Thus, an application must provide a corresponding dialog box template.) Windows displays the configuration dialog box when the user chooses the Setup button in the Screen Saver box in the Desktop application in Control Panel. The data entered by the user with the configuration dialog box is stored in the REGEDIT.INI file.

The third required function in a screen saver module is RegisterDialogClasses. This function must be called by all screen saver applications. However, applications that do not require special windows or custom controls in the configuration dialog box can simply return TRUE. Applications requiring custom controls or special windows should use this function to register the corresponding window classes.

In addition to creating a module that supports the three functions just described, a screen saver should supply an icon. This icon is visible only when the screen saver is run as a standalone application. (To be run by Control Panel, a screen saver must have the .SCR filename extension; to be run as a standalone application, it must have the .EXE filename extension.) The icon must be identified in the screen saver's resource file by the constant ID_APP, which is defined in the header file SCRNSAVE.H.

One final requirement is a screen saver description string. The resource file for a screen saver must contain a descriptive string that Control Panel displays as the screen saver name. The description string must be the first string in the resource file's string table (identified with the ordinal value 1).

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database