Forum Home
Press F1
 
Thread ID: 24672 2002-09-16 07:31:00 How do I make a screen saver? Sam H (525) Press F1
Post ID Timestamp Content User
79991 2002-09-16 07:31:00 What I'm wanting to know is how to make screen savers? I know there are some programs available to make screen savers out of like photos and pictures you have on you hard drive, but I want to know how they are programmed from scratch. I have some limited C, C++, BASIC and Pascal programming experience if that helps (and I do mean limited experience) , any one know how I can do it? Sam H (525)
79992 2002-09-16 08:45:00 Search on google for scrnsave.h

You'll find several useful links e.g.
dspace.dial.pipex.com

Alternatively, get the book
Windows 98 programming from the ground up
by Herbert Schilt
There's an example in it.

Graeme
Graeme (1537)
79993 2002-09-16 08:59:00 www.freebyte.com John Grieve (367)
79994 2002-09-16 09:05:00 cannot seem to make that link work properly so although I don't like doing this heres a copy of the page .

How to make a Windows Screensaver .
version 1 . 1, august 1997
by Henk Hagedoorn
Mail



This page is hosted by
Freebyte!,
Your guide to the Web .



Background
Windows screen saver is basically just a standard Windows executable that has been renamed to have a . SCR filename extension . In order to interface properly with the Control Panel Desktop, however, certain requirements must be met . Because my primary knowledge is programming with Delphi, the illustrating code snipplets are in Delphi . If you use another language you best use the online help, books or manuals to search for the right procedures . But the programming principles and Windows API calls remain the same in all programming environments .

In general, the screensaver program must:

maintain optional settings
provide a description of itself
distinguish between active mode and configuration mode
disallow multiple copies of itself to run
exit when the user presses a key or moves the mouse .
In the following description, I will try to show how each of these requirements can be met using Delphi 16 bit and 32 bit . There are two forms to be created for the screensaver .

Configuration Form
The first thing most people see of a screen saver is its setup dialog . This is where the user specifies values for options specific to the screensaver . These options have to be stored in an ini file, or even better: the control . ini file in the windows directory . Your programming package (Visual basic, Delphi, etc) will have methods to access ini files .

Screen Saver Form
The screen saver itself will simply be a large, black, captionless form in which something will be drawn . The form has to fill the entire screen so it must be maximized . Also it has to stay on top of any other form in any other application . The screensaver form has to be closed if a key is pressed or the mouse is moved . The method for this will depend on your programming environment . For the mouse, you will have to compare the new mouse coordinates with the old ones .

The Screen Saver Description
The description is simply the text that will appear in the control panel desktop list of screen savers . Here is the method for defining a screensaver description in Delphi . This is not an essential part . If left out, the screensaver filename will be in the control panel list .
In Delphi it is done by adding a {$D text} directive to the project sourcefile, like this:


{$D SCRNSAVE My screensaver}


The text "My screensaver" will appear in the Control Panel list of available screen savers when we complete the project . In Visual Basic or another programming environment, you have to find out for yourself how to do this . The $D directive inserts the given text into the module description entry of the executable file . For the Control Panel to recognize the text you must start with the term "SCRNSAVE", followed by your description .

Active Versus Configuration Mode
Windows launches the screen saver program under two possible conditions:

when the screen saver is activated
when the screen saver is to beconfigured .
In both cases, Windows runs the same program . It distinguishes between the two modes by adding a command line parameter: "/s" for active mode and "/c" for configuration mode . For our screen saver to function properly with the Control Panel, it must check the command line for these switches .
In 32 bit code check only chars1 to 2, because some other information is added after /c and /s . For all versions of Windows the following Delphi code example should work:



var param1Str: string;
{ . . }
if ParamCount > 0 then begin
param1Str := lowercase(copy(paramStr(1), 1, 2));
if param1Str = '/c' then
DoConfigurationScreen
else if param1Str = '/s'
DoScreensaverDisplay;
end;



Adapt this code when using another programming tool, like VB .

Active Mode
When the screen saver enters active mode (/s), we need to create and show the screen saver form . When the screen saver form closes, the entire program should then terminate .

Configuration Mode
When the screen saver enters configuration mode (/c), we need to create and show the configuration form . We should also create the screen saver form, in case the user wishes to test configuration options . However, when the configuration form closes, the entire program should then terminate .

Blocking Multiple Instances
One difficulty with Windows screen savers is that they must prevent multiple instances from being run . Otherwise, Windows will continue to launch a screen saver as the given time period elapses, even when an instance is already active . To block multiple instances of our screen saver in 16 bit code (Delphi example), put the following into the project file:



var param1Str: string;
begin {Only one instance is allowed at a time . }
if hPrevInst = 0 then
begin
if (ParamCount > 0) then
param1Str := lowercase(copy(paramStr(1), 1, 2));
if (Param1Str = '/s') then
{start the screensaver form}
else
{start the configuration form}
else
{start the configuration form}
end
else
{do not continue the application: close it}
end .



The hPrevInst is an API function which points a previous instance of the current program . It will be zero if there are no previous instances still running .

NOTE: While creating Delphi 32 bit screensavers, the API routine hPrevInst does not work . You should use the API routines CreateMutex and OpenMutex (with a unique string) to determine previous instances running .

In Visual Basic, Borland C++, etc . you have to find out for yourself how to be able to determine if more instances of your program are running, but probably you can use the same API routine .


Installation
Simply copy the executable file to the Windows directory . Change its filename extension to . SCR . Then, launch the Control Panel, double-click on Desktop, and select Screen Saver Name . You should see "My screensaver" in the list of possible screen savers . Select it and set it up . In Windows 3 it might be necessary to have to restart windows before the control panel sees the new screensaver .
John Grieve (367)
79995 2002-09-16 09:11:00 John, long links need to be enclosed in the formatting options.

The link is here (www.freebyte.com)

When they wrap in the input box they get spaces added which show as %20 in the url.

Use the [ u r l = http--etc ] your text [/ u r l ] (I have shown spaces to prevent it treating it as a real format request)
godfather (25)
79996 2002-09-16 09:22:00 Thanks godfather. As you can tell from all the "broken" links I post I had no idea a long link could/would be a problem. John Grieve (367)
79997 2002-09-16 11:47:00 I took a C++ project renamed it from *.EXE to *.SCR put it in with all the other *.SCR files, selected it as a screen saver and waited ....................
It worked, but ........... it was the most pathic screen saver I have ever seen.
E.ric (351)
1