Board index » delphi » Is Screen Saver Active ???

Is Screen Saver Active ???

I am trying to find out if the screen saver is currently active (running) or
not on Windows 95, 98, NT, 2000 PCs, using Delphi 5.

I have used the API calls, as recommended by :
  * Borland's FAQ 2450D
  * The Tomes of Delphi 3 : Win 32 Core API  (p 727)

and have come up with this code :

Function WIN_API_INC__Is_Screen_Saver_Active : Boolean;
var
   SS_Running : Boolean;
begin
     result := False;

     if SystemParametersInfo (SPI_GETSCREENSAVEACTIVE, 0, @SS_Running, 0) =
True then
     begin
          { Function call to SystemParametersInfo succeded }

          If SS_Running = False then
             result := False       { Screen Saver *IS NOT* running }
          Else
             result := True;       { Screen Saver *IS* running }
     end;
end;

The problem is that this code does NOT work on Windows 98, and I would guess
that it doesn't work on other platforms (e.g. NT).  (The function says that
the screen saver is always running - even when it isn't).

Does anyone have any ideas on what is needed / missing ?

TIA

 Mike "Moose" O'Malley

 

Re:Is Screen Saver Active ???


My Win32.hlp file says "if the function succeeds the return value is
non-zero".  

Perhaps under Win98 it returns something other than "True" ?  Try
typecasting SS_Running as a byte or word and checking the numerical
value.

In any case, I tested your function with NT 4  and it seems to work.

Rob

Quote
Moose wrote:

> I am trying to find out if the screen saver is currently active (running) or
> not on Windows 95, 98, NT, 2000 PCs, using Delphi 5.

> I have used the API calls, as recommended by :
>   * Borland's FAQ 2450D
>   * The Tomes of Delphi 3 : Win 32 Core API  (p 727)

> and have come up with this code :

> Function WIN_API_INC__Is_Screen_Saver_Active : Boolean;
> var
>    SS_Running : Boolean;
> begin
>      result := False;

>      if SystemParametersInfo (SPI_GETSCREENSAVEACTIVE, 0, @SS_Running, 0) =
> True then
>      begin
>           { Function call to SystemParametersInfo succeded }

>           If SS_Running = False then
>              result := False       { Screen Saver *IS NOT* running }
>           Else
>              result := True;       { Screen Saver *IS* running }
>      end;
> end;

> The problem is that this code does NOT work on Windows 98, and I would guess
> that it doesn't work on other platforms (e.g. NT).  (The function says that
> the screen saver is always running - even when it isn't).

> Does anyone have any ideas on what is needed / missing ?

> TIA

>  Mike "Moose" O'Malley

Re:Is Screen Saver Active ???


Quote
"Moose" wrote:
> I am trying to find out if the screen saver is currently active
(running) or
> not on Windows 95, 98, NT, 2000 PCs, using Delphi 5.
<snip>
>      if SystemParametersInfo (SPI_GETSCREENSAVEACTIVE, 0,

@SS_Running, 0) =
<snip>

Quote
> The problem is that this code does NOT work on Windows 98, and I
would guess
> that it doesn't work on other platforms (e.g. NT).  (The function
says that
> the screen saver is always running - even when it isn't).

> Does anyone have any ideas on what is needed / missing ?

The SystemParametersInfo() just tells you if a screensaver is
_enabled_, what means, it will be launched after a while. It does not
tell if it is _running_ at the very moment.
If this is what you're after, then you could catch the system message
about like this:
{----------}
TForm1 = class(TForm)
  {...}
  procedure WMSysCommand(var Message: TWMSysCommand); message
WM_SYSCOMMAND;
end;
{...}
procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
begin
  if Message.CmdType AND $FFF0 = SC_SCREENSAVE then { ssaver is
starting }
   else inherited;
end;
{----------}

HTH
-ThomasN

Re:Is Screen Saver Active ???


Quote
"Moose" <mo...@move.to> wrote in message

news:98na1b$ma6$1@spider.cqu.edu.au...

Quote
> Function WIN_API_INC__Is_Screen_Saver_Active : Boolean;

var    ssRunning : LongBool;

begin
result := SystemParametersInfo (spi_GetScreenSaveActive, 0, @ss_Running, 0)
and ss_Running;
end;

Re:Is Screen Saver Active ???


The message <98na1b$ma...@spider.cqu.edu.au>
  from  "Moose" <mo...@move.to> contains these words:

Quote
>     if SystemParametersInfo (SPI_GETSCREENSAVEACTIVE, 0, @SS_Running, 0) = True

Hi, just a hunch but some windows functions have caused me problems.
The return type
of Windows functions is longbool which is 4 bytes, Whereas the
constants True and False
in Delphi are 1 byte. (Try the SizeOf function on them). Their values are

       False=$00000000 and True = $00000001.

The win32 API is written in C (or C++) and C does not have a boolean
type. C basically
takes zero as meaning False and Non-Zero as meaning true. to check
for True you need,

      if SystemParametersInfo (SPI_GETSCREENSAVEACTIVE, 0,
@SS_Running, 0) <> longbool(0)

and to check for false you need

      if SystemParametersInfo (SPI_GETSCREENSAVEACTIVE, 0,
@SS_Running, 0) = longbool(0)

A typecast like longbool(TRUE), or longbool(1) seems to  work as
well, so I guess the
compiler just needs both values to be longbool in order to fix up the
comparison in
the right way.

--
Sincerely,

Andreas Kyriacou
----------------
http://www.andrikkos.co.uk

Other Threads