The best way to learn how to use the WebCore is by example. See the documentation for more information.
The requested URL is always shown first; if a page uses one or more WebCore templates, those are shown afterwards.
00 <?php
01 include_once ('software/init.php');
02
03 $Page->title->subject = 'Screen Saver Documentation';
04
05 $Page->location->append ('Software', '../');
06 $Page->location->append ('Delphi');
07 $Page->location->append ('Screen Saver Library', './');
08 $Page->location->append ('Documentation');
09
10 $Page->start_display ();
11 ?>
12 <div class="main-box">
13 <div class="text-flow">
14 <h2>A Screen Saver class library</h2>
15 <p>A screen saver provides four services: preview, configuration, password change
16 and running the screen saver itself. The system starts the screen saver with
17 a command-line parameter to indicate which service to provide. Some of the services
18 also make use of a second command-line parameter which is a window handle. Extra
19 steps have to be taken in order to debug the screen saver when providing these
20 services (<a href="#debugging">Debugging your screen saver</a>).</p>
21 <h3>The Screen Saver</h3>
22 <p><code>TScreenSaver</code> extracts the command line parameter
23 and creates the object that handles the specified service, as shown in <a href="#listing_1">Listing
24 1</a>.</p>
25 <p>To create your own screen saver, derive from <code>TScreenSaver</code>
26 and override the abstract methods <span class="reference">MakePreviewMode</span>,
27 <span class="reference">MakeSaverMode</span>, <span class="reference">MakePasswordMode</span>
28 and <span class="reference">MakeConfigMode</span>.</p>
29 <h3>Config mode</h3>
30 <p><code>TConfigMode</code> provides a window handle that is extracted
31 from the command line parameters. However, the window handle is undocumented
32 and I am unsure what its use is. It's available in the Handle property if a
33 use for it arises. <code>TFormConfigMode</code> displays a single
34 form. For most screen savers this should suffice. Simply pass the name of your
35 form class to the constructor <span class="reference">Create</span>.</p>
36 <h3>Password mode</h3>
37 <p>If a password is enabled for the screen saver, then Windows asks the screen
38 saver to set it. <code>TPasswordMode</code> uses a <code>TScreenSaverPassword</code>
39 which is initialized to a <code>TDefaultScreenSaverPassword</code>
40 object by default. This class uses Windows routines to store and retrieve a
41 password. <code>TScreenSaverForm</code> also uses it by default
42 to check the password before exiting. If you want to provide your own password
43 storage/retrieval mechanism, then make a new descendent of <code>TScreenSaverPassword</code>
44 and override <span class="reference">MakePassword</span> in <code>TPasswordMode</code>.</p>
45 <h3>Preview mode</h3>
46 <p>When the user selects a screen saver, Windows tells it to show a preview on
47 the 'Display Properties' dialog. The system passes the window handle in which
48 to display on the command line. Any application responding to it must idle until
49 the window becomes visible, display the preview, then exit when the window is
50 hidden.</p>
51 <p><code>TPreviewMode</code> handles this in <a href="#listing_2">Listing 2</a>.
52 The <span class="reference">Start</span>, <span class="reference">Step</span>,
53 and <span class="reference">Stop</span> methods are filled in by descendents.
54 For example, <code>TCanvasPreviewMode</code> prepares a <span class="field">TCanvas
55 </span>that paints on the preview window. Descendents need only redefine <span class="reference">Step</span>
56 to provide the custom painting. <code>TWinControlPreviewMode</code>
57 attaches a windows control to the preview window, sizing it correctly and displaying
58 it.</p>
59 <h3>Saver mode</h3>
60 <p>The screen saver should guard against being launched full screen multiple times.
61 Windows will usually try at least once to relaunch the saver once it is running.
62 If the saver allows multiple instances to be launched, Windows will launch again
63 for the new instance and soon dozens of instances will be running. <code>TSaverMode</code>
64 prevents multiple launches with a <code>TPreviousInstance</code>,
65 which uses a Windows atom to guarantee detect previous instances, as shown in
66 <a href="#listing_3">Listing 3</a>.</p>
67 <p>Descendant classes override the <span class="reference">OnExecute</span> method
68 to display the screen saver itself. The behavior of a standard screen saver
69 is encapsulated in <code>TScreenSaverForm</code>, which automatically
70 grows to the size of the screen and takes care of detecting mouse movements
71 and keystrokes. When user action is detected, it closes if the password (if
72 enabled) is properly entered. Most screen savers will be able to customize this
73 form.</p>
74 <p><a href="#listing_4">Listing 4</a> shows the Descendant forms should provide
75 startup code in <span class="reference">SetUpScreenSaver</span>, because overriding
76 <span class="reference">OnFormCreate</span> doesn't work. <span class="reference">DetectMouse</span>
77 and <span class="reference">DetectKeyboard</span> can also be customized. They
78 both return True by default. <span class="reference">Password</span> is initialized
79 to <code>TDefaultScreenSaverPassword</code> by default, which
80 simply uses the default Windows screen saver password.</p>
81 <p><code>TFormSaverMode</code> displays a single form. If you only
82 want to display a form for the screen saver, then pass the name of your form
83 class to the constructor <span class="reference">Create</span>.</p>
84 <h3><a name="debugging"></a>Debugging</h3>
85 <p>[not finished]</p>
86 <h2>Using the Screen Saver Library - Flash Screen Saver</h2>
87 <p>The screen saver library provides a layer that creates a working screen saver.
88 It's up to descendant classes to build on this layer to create a useful screen
89 saver. Most screen savers display some sort of repeating animation. For this
90 purpose, the Flash® player from Macromedia is ideal. It is also packaged
91 as an ActiveX® control, and is easily imported into Delphi.</p>
92 <p>We'll want the user to be able to select a Flash® file to play as well
93 as play that file in the preview mode as well as the screen saver mode. We will
94 make use of several classes from the library, including <code>TScreenSaver</code>,
95 <code>TScreenSaverForm</code>, <code>TFormConfigMode</code>,
96 <code>TPasswordMode</code>, <code>TWinControlPreviewMode</code>
97 and <code>TFormSaverMode</code></p>
98 <p>What about playing the Flash file at original size?</p>
99 <h2>Listings</h2>
100 <h3 id="listing_1">Listing 1</h3>
101 <pre><code><span class="reserved">constructor</span> TScreenSaver.Create;
102 <span class="reserved">var</span>
103 command: <span class="reserved">string</span>;
104 <span class="reserved">begin</span>
105 command := UpperCase (ParamStr (1));
106 <span class="reserved">if</span> is_switch (command, 'P') <span class="reserved">then</span>
107 FMode := MakePreviewMode
108 <span class="reserved">else if</span> is_switch (command, 'S') <span class="reserved">then</span>
109 FMode := MakeSaverMode
110 <span class="reserved">else if</span> is_switch (command, 'A') <span class="reserved">then</span>
111 FMode := MakePasswordMode
112 <span class="reserved">else if</span> is_switch (command, 'C') <span class="reserved">or</span> (command = '') <span class="reserved">then</span>
113 FMode := MakeConfigMode;
114 <span class="reserved">end</span>;</code></pre>
115 <h3 id="listing_2">Listing 2</h3>
116 <pre><code><span class="reserved">procedure</span> TPreviewMode.Execute;
117 <span class="reserved">begin</span>
118 <span class="reserved">while</span> <span class="reserved">not</span> IsWindowVisible (Handle) <span class="reserved">do begin</span>
119 Application.ProcessMessages;
120 <span class="reserved">end</span>;
121 <span class="reserved">try</span>
122 Start;
123 <span class="reserved">while</span> IsWindowVisible (Handle) <span class="reserved">do</span> <span class="reserved">begin</span>
124 Step;
125 Application.ProcessMessages;
126 <span class="reserved">end</span>;
127 <span class="reserved">finally</span>
128 Stop;
129 <span class="reserved">end</span>;
130 <span class="reserved">end</span>;</code></pre>
131 <h3 id="listing_3">Listing 3</h3>
132 <pre><code><span class="reserved">procedure</span> TSaverMode.Execute;
133 <span class="reserved">var</span>
134 finder: TAppFinder;
135 <span class="reserved">begin</span>
136 finder := TAppFinder.Create;
137 <span class="reserved">try</span>
138 <span class="reserved">if</span> finder.exists <span class="reserved">then</span>
139 finder.select_existing_app
140 <span class="reserved">else</span>
141 OnExecute;
142 <span class="reserved">end</span>;
143 <span class="reserved">finally</span>
144 finder.Free;
145 <span class="reserved">end</span>;
146 <span class="reserved">end</span>;</code></pre>
147 <h3 id="listing_4">Listing 4</h3>
148 <pre><code>TScreenSaverForm = <span class="reserved">class</span> (TForm)
149 <span class="comment">{code omitted}</span>
150 <span class="reserved">protected</span>
151 <span class="reserved">procedure</span> SetupScreenSaver; <span class="reserved">virtual</span>;
152 <span class="reserved">function</span> MakePassword: TScreenSaverPassword; <span class="reserved">virtual</span>;
153 <span class="reserved">function</span> GetDetectMouse: Boolean; <span class="reserved">virtual</span>;
154 <span class="reserved">function</span> GetDetectKeyboard: Boolean; <span class="reserved">virtual</span>;
155 <span class="reserved">public</span>
156 <span class="reserved">property</span> DetectMouse: Boolean <span class="reserved">read</span> GetDetectMouse;
157 <span class="reserved">property</span> DetectKeyboard: Boolean <span class="reserved">read</span> GetDetectKeyboard;
158 <span class="reserved">end</span>;</code></pre>
159 </div>
160 </div>
161 <?php $Page->finish_display (); ?>
162