Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Write a Screensaver in Delphi Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-Jun-02
Category
System
Language
Delphi 3.x
Views
96
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Dave Murray

How to Write a Screensaver in Delphi

Answer:

In order to write a screensaver we need to include several procedures: 

FormShow - hide cursor, setup message processing, start screensaver display 
FormHide - stop screensaver display, show cursor 
DeactivateScrSaver - process messages, deactivate if keys / mouse pressed 

Typical code for these procedures is shown below. 

You should ensure that your form is designed with the style fsStayOnTop. You also 
need to make sure only one instance of your program is running in the usual way. 
Finally you need to include the compiler directive {$D SCRNSAVE programname Screen 
Saver} in your project unit (*.dpr). 

Once your program is compiled then change it's filename extension to SCR and copy 
it to your \WINDOWS\SYSTEM folder. 

If running on Windows 98 you must disable the screensaver calls when it is running. 
I have not needed to do this for versions of windows prior to 98 but it should work 
on all versions. To do this insert the following call into your FormCreate method: 
1   
2   SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, nil, 0);
3   
4   //You must reverse this in your FormClose method: 
5   
6   SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, nil, 0);
7   
8   var
9     crs: TPoint; {original location of mouse cursor}
10  
11  procedure TScrForm.FormShow(Sender: TObject);
12  {starts the screensaver}
13  begin
14    WindowState := wsMaximized; {ensure program fills screen}
15    GetCursorPos(crs); {get current cursor position}
16    Application.OnMessage := DeactivateScrSaver; {check for Mouse/Keys}
17    ShowCursor(false); {hide the cursor}
18    {start screensaver display...}
19    //
20  end; {procedure TScrForm.FormShow}
21  
22  procedure TScrForm.FormHide(Sender: TObject);
23  {returns control to the user}
24  begin
25    Application.OnMessage := nil; {discard the message}
26    {stop the screensaver...}
27    //
28    ShowCursor(true); {bring the cursor back}
29  end; {procedure TScrForm.FormHide}
30  
31  procedure TScrForm.DeactivateScrSaver(var Msg: TMsg; var Handled: boolean);
32  {detects Mouse movement or Keyboard use}
33  var
34    done: boolean;
35  begin
36    if Msg.message = WM_MOUSEMOVE then {mouse movement}
37      done := (Abs(LOWORD(Msg.lParam) - crs.x) > 5) or
38        (Abs(HIWORD(Msg.lParam) - crs.y) > 5)
39    else {key / mouse button pressed?}
40      done := (Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP) or
41        (Msg.message = WM_SYSKEYDOWN) or (Msg.message = WM_SYSKEYUP) or
42        (Msg.message = WM_ACTIVATE) or (Msg.message = WM_NCACTIVATE) or
43        (Msg.message = WM_ACTIVATEAPP) or (Msg.message = WM_LBUTTONDOWN) or
44        (Msg.message = WM_RBUTTONDOWN) or (Msg.message = WM_MBUTTONDOWN);
45    if done then
46      Close;
47  end; {procedure TScrForm.DeactivateScrSaver}


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC