Solved

Terminating a screensaver..

Posted on 1997-11-14
8
320 Views
Last Modified: 2010-04-04
Hello,

Is it possible to detect if a screensaver is running ?
and if it is running can i terminate it even if it has an password ?

Procedure TNoteBoxMain.BreakScreenSaver;
Var
  Point: TPoint;
  WHandle: THandle;
Begin
  With Point do Begin X:= 16; Y:= 16; end;
  WHandle:= WindowFromPoint(Point);
  SendMessage(WHandle,WM_MBUTTONDOWN,0,255);
End;

this procedure terminates a screensaver with no password, but is has no detecting if a screensav is running
and when then screensav has a password it show the dialog box to enter the password.

Any help would be appreciated..
0
Comment
Question by:mories
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 1

Expert Comment

by:mortenmo
ID: 1350404
Yep.. When you have password set it will always prompt on
a normal attempt to close the program..

However you can kill the program brutally (and therefor skip the
password part even if it is set)..

Use this SendMessage line instead:

 SendMessage(WHandle,WM_DESTROY,0,0);

Hope this helps..
0
 
LVL 1

Author Comment

by:mories
ID: 1350405
But what if i don't know the handle of the screensaver i don't even know what and if a screensaver is installed...
0
 
LVL 1

Expert Comment

by:mortenmo
ID: 1350406

Ups forgot that.. Here is what you can do..
 
--------
  SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, @dummy, 0);

  if dummy = 0 then begin
    With Point do Begin X:= 16; Y:= 16; end;
    WHandle:= WindowFromPoint(Point);
    Debug.Text := 'Screensave destroyed';
    SendMessage(WHandle,WM_DESTROY,0,0);
  end else
    Debug.Text := 'No screensaver';
-------

SystemParametersInfo(SPI_GETSCREENSAVEACTIVE,.. returns 0 if there is a screensaver currently running and 1 if there is no
screen saver running..

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:mortenmo
ID: 1350407
You can use TerminateProcess(WHandle) too tho..

But of course you should try to close it nicely first..
SendMessage(WHandle, WM_CLOSE, 0, 0); will ask it to die, but
if a password is set it wont close. Then you should send
WM_DESTROY

0
 
LVL 1

Author Comment

by:mories
ID: 1350408
I think this one is not very easy,

this SPI_GETSCREENSAVEACTIVE only looks if a screensaver is configured, it doesn't check if the screensaver is running.

you can test it if you put this in an OnClick event.

I hope this one can be solved.
0
 
LVL 1

Expert Comment

by:mortenmo
ID: 1350409
Hmm.. Well since the screensaver always is the highest window
I guess this should work if you don't want to use
the point hack.

----------------
if dummy = 0 then begin
  WHandle := GetTopWindow(0);
  Debug.Text := 'Screensave destroyed';
  SendMessage(WHandle,WM_DESTROY,0,0);
end else
  Debug.Text := 'No screensaver';
end;
--------------------------
0
 
LVL 1

Expert Comment

by:mortenmo
ID: 1350410
Are you sure?

I actually tried that SPI_GETSCREENSAVEACTIVE and it did return 0 when a screensaver were running and 1 if no were.

Lemme test some more..



0
 
LVL 2

Accepted Solution

by:
alona041797 earned 100 total points
ID: 1350411
The window title of a screen saver is "Screen Saver". You can use FindWindow to locate its handle and whether or not it's running, and then destroy it.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question