The method ScreenSaverForm_Load prepares everything before the animation drawing takes place. If the system calls the screen saver in preview mode, it passes this handle as the second argument after /p (see Microsoft Support). The constructor gets an integer passed, which is the Windows handle for a possible preview window. All of the objects that are needed for the animation by the different screen savers are in the internal class Globals. The actual screen saver animation drawing is done in a derived class from ScreenSaverBase. It prepares and handles everything needed.
ScreenSaverForm is the form of the application.
Also, if we have just little parts on the screen that change in every animation step, we can directly update these parts and don't have to refresh the full screen. This means that we don't use the paint event handler to draw our animation we can do it directly in the timer event handler. Either the screen saver is on and the full screen is ours, or it is off. The big difference between a screen saver application and a normal Windows application is that we have the full screen for us when it's running, so we don't have to be able to re-draw any part of the client area in a paint event handler.
Using the Code Difference to a Normal Application Makes it easy to handle different animations.Has the possibility to switch off the screen saver after awhile.Handles everything needed to set up a screen saver, so one can concentrate on a new animation.Supports the preview possibility in the desktop screen saver properties.My intention was not to write an application with high quality and/or fancy-rendering OpenGL or DirectX animations (there are hundreds to find on the web). There's no support for the preview possibility in the desktop screen saver properties.It refreshes the screen at every single step of an animation doing this every 50 ms ends in more CPU usage than normal idle mode (my PC changed from about 0-2% up to 60%, which switched on the ventilator).I started with the Screen Saver Starter Kit that comes with Visual Studio 2005, but wasn't happy with how they implemented it. I wanted to write a simple screen saver by myself: worms. This code simplifies the necessary steps to an absolute minimum. It handles the arguments passed to a screen saver application by the system, which includes the preview in the desktop screen saver property dialog, as well as a configuration dialog. This starter kit and sample code can be used as a starter project to write your own screen saver.