Windows Programming/Programming Screensavers< Windows Programming
Screensavers are graphical programs that will exercise the computer's screen while the computer is not in use, to prevent damage to the screen. Screensavers can also be very aesthetic, interesting, and entertaining however.
Screensaver programs are essentially normal executable programs, with a few small differences:
- They have a .scr extension, instead of a .exe
- They have a ScreenSaverProc, instead of a WindowProc.
- They call DefScreenSaverProc, instead of DefWindowProc.
Also, screensavers must contain a configuration dialog box, that the shell can call when you click on the screensaver and select "properties". The last requirement is that a screensaver must have a string resource, at resource 1, with a description of the screensaver.
How they WorkEdit
Windows will send a number of different arguments to a screensaver, on the commandline, depending on what mode of operation the screensaver must take. Here are some of them:
- /a <hwnd>
- /c <hwnd>
- /p <hwnd>
The -a option tells the screensaver program to set the associated password, if the screensaver is selected to be password protected. The -s option tells the screensaver to run the graphics, and start saving the screen. The -c option tells the screensaver to display the configuration dialog, and the -p option tells the screensaver to run in preview mode.
The WinMain function should decode the command line, and obtain both the switch (a, s, p, c) and the handle, if specified. The Handle value will be in an ascii string, so that will need to be converted to an integer, and stored into an appropriate HWND variable. The handle provided is the handle to the parent window of the screensaver, which is usually the screensaver tab in the Windows Display dialog box. The screensaver doesn't have a parent window if it is in screensaving mode.
If WinMain has received a -s or a -p, the WinMain should call the ScreenSaverProc. If it has received the -c option, WinMain should call the Dialog box procedure function. If the screensaver receives the -a option, it should bring up a dialog to change the password.