Disabling ScreenSaver

How to I disable a screensaver?  I want to turn off the screen saver while a portion of my program is running.  
Thanks.
newindAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
intheConnect With a Mentor Commented:
hi newwind,
no your correct application.handle wont do it.

also ..sc_screensave,0) is fine for starting it but not for stopping it.
i tried ..sc_screensave,1)  and it brought up the shutdown screen :o]

to stop it its better to use something like:

keybd_Event(ord('X'), 0, 0, 0);{key down}
keybd_Event(ord('X'), 0, KEYEVENTF_KEYUP, 0);{key up}

this just sends a keypress which stops it same as sending a mousemove message..
0
 
rwilson032697Commented:
You certainly can prevent the computer's screen-saver from starting.
Declare a message handler for your form like this -

procedure WMSysCommand (var Msg: TWMSysCommand); message WM_SYSCOMMAND;

  And then, implement the following in the body of your code -

procedure TTraceMeFrm.WMSysCommand (var Msg: TWMSysCommand);
begin
  if Msg.cmdType = SC_ScreenSave then
    Msg.Result := -1
  else
    inherited
end;

  This will prevent the Windows screen saver from running while your application is running.

Cheers,

Raymond.

0
 
intheCommented:
Listening..
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
newindAuthor Commented:
Thanks Raymond.  However, I don't want to turn off the screen saver while my app is running.  In fact my app runs on a server, thus it has to be running all the time.  What I want is to disable the screensaver while a portion of my app is running.  How do I do this?
0
 
rwilson032697Commented:
Perhaps this change might help...

procedure TTraceMeFrm.WMSysCommand (var Msg: TWMSysCommand);
begin
  if (Msg.cmdType = SC_ScreenSave) AND
      SuppressTheScreenSaver then    
    Msg.Result := -1
  else
    inherited
end;

Where SuppressTheScreenSaver is a boolean you set to true while the portion of your program is running that shoudl stop the screensaver from running...

Cheers,

Raymond.

0
 
intheCommented:
Hi
You could temporarily turn off screen saving like this:

  {Turn screen saving off}
  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,0,nil,0);
  try
    {Do the job where screen saving not required}
     
  finally
    {Turn screen saving on again}
    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,nil,0);
  end;


Other ideas Would be :
this would force the default screensaver to start:

  SendMessage(Application.Handle,WM_SYSCOMMAND,SC_SCREENSAVE,0);
 
And this will cause the screensaver which has started to stop:

  SendMessage(Application.Handle,WM_SYSCOMMAND,SC_SCREENSAVE,1);

Regards Barry
0
 
rwilson032697Commented:
Barry, does SPI_SETSCREENSAVEACTIVE work in NT?

Cheers,

Raymond.
0
 
DrDelphiCommented:
I have a nifty little examples of two ways of disabling the screensaver on my website:

www.drdelphi.com.


Good luck!!
0
 
intheCommented:
Hi Raymond
yes about half the SPI_* messages work in nt including SPI_SETSCREENSAVEACTIVE

see win32.hlp file under SystemParametersInfo for details ..
Regards
0
 
intheCommented:
tried and tested:

  {Temporarily turn screen saver off}
  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,0,nil,0);
  try

    {Do the code here}
     
  finally
    {Turn screen saver on again}
    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,nil,0);
  end;
0
 
intheCommented:
ps dr delphi
did you make the search for your website?
looking for one myself ,i dont think the new server im moving to supports frontpage extensions which i used for my search. suppose i need a cgi one.
0
 
DrDelphiCommented:
inthe,
  I leeched it from a JavaScript website. There is no CGI used in it at all. I like it because it is fast.
0
 
newindAuthor Commented:
Thanks Barry.  I'm already inclined to give you the points. I  think the one of SystemParametersInfo will work indeed.   But one last question.  To stop the currently running screensaver you said I can use SendMessage(Application.Handle,WM_SYSCOMMAND,SC_SCREENSAVE,0);
I tried it and it didn't work.  Is Application.Handle MY App's handle?
0
 
craig_capelCommented:
unit Unit1;

 interface

 uses
   Windows, Messages, SysUtils, Classes,
   Graphics, Controls, Forms, Dialogs;

 type
   TForm1 = class(TForm)
   private
     procedure WMSysCommand(var Msg : TWMSysCommand);
               message WM_SYSCOMMAND;
   public
     { Public declarations }
   end;

 var
   Form1: TForm1;

 implementation

 {$R *.DFM}

 procedure TForm1.WMSysCommand(var Msg : TWMSysCommand);
 begin
   //trap the message and set its result to -1
   if (Msg.CmdType = SC_SCREENSAVE) then
     Msg.Result := -1
   else
     inherited;
 end;

 end.


IT may work in NT? try it....

Craig C.
0
 
craig_capelCommented:
ah, sorry never read as to why this would not work..... how about a little if statement?

unit Unit1;

 interface

 uses
   Windows, Messages, SysUtils, Classes,
   Graphics, Controls, Forms, Dialogs;

 type
   TForm1 = class(TForm)
   private
     procedure WMSysCommand(var Msg : TWMSysCommand);
               message WM_SYSCOMMAND;
   public
     { Public declarations }
   end;

 var
   Form1: TForm1;

 implementation

 {$R *.DFM}

 procedure TForm1.WMSysCommand(var Msg : TWMSysCommand);
 begin
   //trap the message and set its result to -1
if   part_of_program_running=false then
  begin
   if (Msg.CmdType = SC_SCREENSAVE) then
     Msg.Result := -1
   else
     inherited;
   end;
  end;
end.

What would be wrong with something like that?
0
 
newindAuthor Commented:
Thanks Barry,
keybd_Event(ord('X'), 0, 0, 0) did work.
Wishing you all the best in your endeavours.
- newind
0
 
newindAuthor Commented:
Thank you to all the experts who tried to help me out.  Good luck to all of you guys!
0
All Courses

From novice to tech pro — start learning today.