Board index » delphi » Detecting screen saver ??

Detecting screen saver ??

Hi Friends,

I want to detect whether the screen saver is actitave now in my
program. First, I put a Timer on the form and write the event handler:

procedure TForm1.Timer1Timer(Sender: TObject);
var
  bScrSaverRunning: Boolean;
begin
  SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, @bScrSaverRunning, 0);
  if bScrSaverRunning then
    memo1.lines.add('running')
  else
    memo1.lines.add('stop');
end;

But...I found whether the screen saver is or not running, the result is
always 'running', and when I actiative the screen saver test in the
'Control Panel' -> 'Screen Saver Setup', result is 'stop'.

So strange, is it the problem of API ??

Please help me, thank you very much. :-)

--
       Kuan-Ta Chen
       Computer Information Association (CIA)
       Dep. of Computer Science 98              Tsing Hua University
       E-Mail : br831...@cs.nthu.edu.tw && k...@cia.club.nthu.edu.tw
       URL    : http://www.cs.nthu.edu.tw/~br831529

 

Re:Detecting screen saver ??


I haven't done this myself, so this is all conjecture, but it seems
likely... Keep in mind that in C, which the API was written in, False is
defined as zero and True is defined as non-zero.  In Pascal, however, the
Boolean type has very finite true and false states, whose internal compiler
representation (for practical purposes) is not known.  It could be these
differences in representation that are causing trouble.  Instead, try
making your Boolean type a word type (as the help indicates the bool
returned in a 16 bit value).  Then, test the value for non-zero or zero to
establish true or false.  I think this will clear up your problem.

--
David S. Becker
ADP Dealer Services (Plaza R&D)
d...@plaza.ds.adp.com
(503)402-3236

Kuan-Ta Chen <Xsha...@cs.nthu.edu.tw> wrote in article
<5abida$...@news.cs.nthu.edu.tw>...

Quote
> Hi Friends,

> I want to detect whether the screen saver is actitave now in my
> program. First, I put a Timer on the form and write the event handler:
[snip]
> But...I found whether the screen saver is or not running, the result is
> always 'running', and when I actiative the screen saver test in the
> 'Control Panel' -> 'Screen Saver Setup', result is 'stop'.

> So strange, is it the problem of API ??

Re:Detecting screen saver ??


Quote
Kuan-Ta Chen wrote:

> Hi Friends,

> I want to detect whether the screen saver is actitave now in my
> program. First, I put a Timer on the form and write the event handler:

> procedure TForm1.Timer1Timer(Sender: TObject);
> var
>   bScrSaverRunning: Boolean;
> begin
>   SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, @bScrSaverRunning, 0);
>   if bScrSaverRunning then
>     memo1.lines.add('running')
>   else
>     memo1.lines.add('stop');
> end;

> But...I found whether the screen saver is or not running, the result is
> always 'running', and when I actiative the screen saver test in the
> 'Control Panel' -> 'Screen Saver Setup', result is 'stop'.

> So strange, is it the problem of API ??

> Please help me, thank you very much. :-)

> --
>        Kuan-Ta Chen
>        Computer Information Association (CIA)
>        Dep. of Computer Science 98              Tsing Hua University
>        E-Mail : br831...@cs.nthu.edu.tw && k...@cia.club.nthu.edu.tw
>        URL    : http://www.cs.nthu.edu.tw/~br831529

Check for message SC_SCREENSAVE.
The current application will receive a syscommand of SC_SCREENSAVE just
before the screen saver is invoked.  If the app wishes to prevent a
screen save, return non-zero value, otherwise call DefWindowProc().
I have implemented this message in C program, it must be a piece of cake
in Delphi.

Re:Detecting screen saver ??


Quote
erik majer (ema...@nicholsinc.com) wrote:

: Check for message SC_SCREENSAVE.
: The current application will receive a syscommand of SC_SCREENSAVE just
: before the screen saver is invoked.  If the app wishes to prevent a
: screen save, return non-zero value, otherwise call DefWindowProc().
: I have implemented this message in C program, it must be a piece of cake
: in Delphi.

  Yes, It works.
  Now I can know when screen saver is start to RUN ..
  But how can I know when screen saver is STOP ??

Re:Detecting screen saver ??


Quote
erik majer (ema...@nicholsinc.com) wrote:

:
: Check for message SC_SCREENSAVE.
: The current application will receive a syscommand of SC_SCREENSAVE just
: before the screen saver is invoked.  If the app wishes to prevent a
: screen save, return non-zero value, otherwise call DefWindowProc().
: I have implemented this message in C program, it must be a piece of cake
: in Delphi.

  But if my application is not active,
  how can I detect whether the screen saver is running ??

--
       Kuan-Ta Chen
       Computer Information Association (CIA)
       Dep. of Computer Science 98              Tsing Hua University
       E-Mail : br831...@cs.nthu.edu.tw && k...@cia.club.nthu.edu.tw
       URL    : http://www.cs.nthu.edu.tw/~br831529

Other Threads