This is just a quick dip at the trot, a basic checklist of things to do for those comfortable with Visual Basic; this isn't intended to be a full step-by-step, but more a basic overview as to the steps inherent in creating an easy 2D animated screen saver using the language. Most of the information is summarized from this site, so if you're a more intermediate VB programmer and need more detail than this concise synopsis, check out that site.
Time Required: Varies
- The basics in this overview will cover how to create a screensaver using sprites that move at random across the screen, bouncing off each other and off the screen's edges. It can be run through simple VB instructions to Windows. The following steps assume a working knowledge of Visual Basic and its terminology.
- To make the screensaver, you'll need three forms and one dialogue box: a main form to act as the screensaver, a config/settings form to let users customize, a change password form, and a password entry dialogue. You can customize the forms and dialogue to look however you wish.
- Your main form's properties should be set as follows:
- You must set your MouseDown, MouseMove, Click, DoubleClick, Keypress, and Keydown events to end the program. This is standard behavior for all screensavers: user activity banishes the screensaver to return to the main interface.
- Remember that to preview your screensaver in the program, the main (sub Main) must be made a child of the preview window. To run your screensaver in the preview window, you'll have to write a call in the preview window's handle to get the window's size and populate a structure within the window's dimensions.
- For parsing command line parameters, Windows uses the following switches to tell the ScreenSaver what to do based on user actions; for a full list, see the detailed instructions.
- The program should be able to check for currently running instances, as Windows will try to continuously send the switch to start the screensaver and will spawn multiple instances. It should also be able to read the registry to see if the screensaver is password-protected, and then call the password dialogue box if it is. One major thing to remember is to disable ctrl+alt+delete and alt+tab while the program is running, or a user can just tab past the screensaver program.
- Set the screensaver to be "always on top", and hide the mouse cursor until it's moved or clicked.
- For the actual screensaver's contents, you would use sprites: bitmap images, at times with transparent areas. These sprites would be controlled by storing their handles/locations in an array, and then calling them from the screensaver's functions.
- Rather than actually layer the sprites over a real desktop, the screensaver should capture an image of the desktop, store it, and then draw the sprites on top of it. The sprite movement and speed can be controlled by a simple algorithm of your choosing, adjusting the x, y, and z (depth of field, determining which is on top) coordinates.
- You should have functions to draw/load the sprites, resize them as necessary, control their movement and speed, redraw them in each frame instance of their movement, and more importantly control their interaction; one function would determine when they "collide" with one another, and another would define the action to take when this happens by updating their x, y, and z positions according to another algorithm of your choosing.
- A similar function should control a sprite's behavior when it hits the edge of the screen. Then the tricky part is creating a function that calls all of the sprite's display and movement functions to completely put together the screensaver's motion; that's what ends up creating the final picture, controlled by the window parameter functions set before.