| Brought to you by Mainstram System Development | |||||||||
|
MSD Home Page Company Profile MSD Whats News MSD Products Tutors & Downloads MSD Delphi Forum Hot Delphi Links MSD Site Map Contact Us |
  |
Tutors & Downloads
January 2000: Windows Screen Savers This tutor focuses on creating Windows Screen Savers. This is to demonstrate that the power of Borland Delphi is not only limited to Database Applications. Check the download section for more Window Screen Saver that was created by Borland Delphi.
Writing a Windows Screen Saver in Borland Delphi.
A Windows Screen Saver is nothing more than just a simple executable application with a "SCR" extension. We can proof that by renaming any Screen Saver Application (SCR) file to have a "EXE" extension. Now, try to execute it by double clicking on the file. So, Delphi can easily create a Windows Screen Saver, just by creating an application with an "EXE" extension and renaming it to a "SCR" extension.
Let us have a look at what Windows expect from a Windows Screen Saver. The other important thing to keep in mind, is the way Windows activates the Windows Screen Saver Application. To activate the Windows Screen Saver, a /s is passed to the application, while on the other hand, a /c is passed to the application, to configure it.
What are Window Messages? OK. Are you ready? Let?s start then. First we create a new application. Set the following properties of the form to the following values:
Event OnShow:
The onShow event triggers the first time the application sets focus to the form. The GetCursorPos saves the cursor position in a variable crs (this variable must be declared in the form by the user), for later use. A message handler is defined and the cursor is set to invisible.
OnHide:
When the application closes, we need to resore all the changes we have made to the system. Restoring the message handler, and showing the cursor again.
The next step may sound very difficult, but it is really very straight forward. We need to create a message handler to process system messages. In order to create message handler, we need to create a Public method called DecativateScrnSaver. Your form?s declaration should look similar to this:
Here is the implementation of our new message handler:
The message handler works by trapping all the Windows Messages, and search for the specific windows message. The first part of the method searches for the WM_MOUSEMOVE message. If that message is found, we know the user moved the mouse. All we need to do is to test if it moved more than 5 pixels. This can be cone by using the variable crs that we initialized in the onActicate event of the application. If it moved more then 5 pixels, we terminate the screen saver. If it was not a mouse move message, we test for a keyboard message. If it was not one of them, we ignore the message, and continue with the Windows Screen Saver routine.And that?s all there is to creating a simple Windows Screen Saver. Now you can add a second form to your application that handles the configuration of the Windows Screen Saver. Talking about Windows Screen Saver Configuration. We still need to modify our Windows Screen Saver application to recognize different Windows Commands from Command Line Parameters. Let?s have a look at our Project Source. It can be found from Project | View Source.
Now you may compile and execute your Windows Screen Saver. If you are lucky enough, the application will compile without any major errors. As soon as you move the mouse, or press a key on the keyboard, the application wil terminte. Now, let's add the final piece of code to make this application a true Windows Screen Saver.The only thing that is needed in your application is the check for multiple instances of the Windows Screen Saver. This can be done with the hPrevInst variable. Simply encapsulate the program source above in this if statement:
This concludes the tutor on creating a Windows Screen Saver in Borland Delphi.
|
|
�MSD (Pty) Ltd., All Rights Reserved. MSD logo are Registered Trademarks of Mainstream System Development. |
Comments & Questions to
The Web Master
01/12/2000 10:30 |