We help IT Professionals succeed at work.

INCREDIBLE nobody knows?- How to show my app if screen saver is active

TomazB
TomazB asked
on
Medium Priority
224 Views
Last Modified: 2010-04-06
If screen saver is active and my app gets something trough serial port or some work in app is done, it should show itself. Is this so hard to achieve that nobody knows how? Anybody........
Comment
Watch Question

Commented:
Actually, I believe that it is "that hard" simply because windows doesn't bother to inform anybody (except the current app that it's about to start a ssaver. Given this i would just assum that there may _always_  be a ssaver running & try faking an event to close the ssaver.  Possibilities include sending your self a WM_KEYDOWN/WM_KEYUP combo, moving the mouse (mouse.cursorPos := point(some_x,some_y) etc. My personal bet would be to just move the mouse 5-10 pixels, enough to quit the saver, not enough to be really distracting if there isn't a ssaver currently running. BTW, I'm not sure (without checking the source) how moving the mouse that way is handled, but if the system is sufficiently conviced that the ssaver should die you could try doing the same thing with the mouse_event api.

GL
Mike

Commented:
mouse_event and keybd_event works both to stop the screen saver, no problem. Doin the same thing...

Regards, Madshi.

Author

Commented:
Metods like:
KeyBd_Event(VK_ESCape,0,0,0);  or
mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);  doesn't work on my NT4 OS.
Am I doing something wrong?
Commented:
Okay, here comes what I'm using. Quite much for 50 points, if you ask me...   :-/

function FindScreenSaverFunc(window: cardinal; found: TPBoolean) : bool; stdcall;
var s1 : string;
begin
  SetLength(s1,MAX_PATH+1);
  SetLength(s1,GetClassName(window,pchar(s1),MAX_PATH));
  found^:=s1='WindowsScreenSaverClass';
  result:=not found^;
end;

function ScreenSaverRunning : boolean;
var c1 : cardinal;
begin
  if OS.winNt then begin
    result:=false;
    c1:=OpenDesktop('Screen-saver',0,false,MAXIMUM_ALLOWED);
    if c1<>0 then
      try
        EnumDesktopWindows(c1,@FindScreenSaverFunc,integer(@result));
      finally CloseDesktop(c1) end;
  end else result:=windows.FindWindow('WindowsScreenSaverClass',nil)<>0;
end;

function CloseScreenSaverFunc(window: cardinal; found: TPBoolean) : bool; stdcall;
var s1 : string;
begin
  SetLength(s1,MAX_PATH+1);
  SetLength(s1,GetClassName(window,pchar(s1),MAX_PATH));
  found^:=s1='WindowsScreenSaverClass';
  result:=not found^;
  if found^ then PostMessage(window,WM_CLOSE,0,0);
end;

function StopScreenSaver : boolean;
var c1 : cardinal;
    b1 : bool;
begin
  result:=ScreenSaverRunning;
  if result then
    if OS.winNt then begin
      result:=false;
      c1:=OpenDesktop('Screen-saver',0,false,DESKTOP_READOBJECTS or DESKTOP_WRITEOBJECTS);
      if c1<>0 then
        try
          EnumDesktopWindows(c1,@CloseScreenSaverFunc,integer(@result));
        finally CloseDesktop(c1) end;
      if result then begin // Neustart der Bildschirmschoner-Timer
        if SystemParametersInfo(SPI_GETSCREENSAVEACTIVE,0,@b1,0) and b1 then
          SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,nil,0);
        if SystemParametersInfo(SPI_GETLOWPOWERACTIVE,0,@b1,0) and b1 then
          SystemParametersInfo(SPI_SETLOWPOWERACTIVE,1,nil,0);
        if SystemParametersInfo(SPI_GETPOWEROFFACTIVE,0,@b1,0) and b1 then
          SystemParametersInfo(SPI_SETPOWEROFFACTIVE,1,nil,0);
      end;
    end else begin
      keybd_event(VK_CONTROL,0,0,              0);
      keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
    end;
end;

Regards, Madshi.

Author

Commented:
Madshi you are right.

Author

Commented:
Thank's Madshi, at last someone who knows the answer that is realy worth of points.

Commented:
Wow, thanx for the point boost...   :-)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.