views:

44

answers:

1

Should have been simple I would have thought. I want to force the PC to go into screen saver mode, and exit it when conditions I am checking in by D2006) app come true. It doesn't seem to work:

    if ScreenSaverExitRequested then
        begin
        SystemParametersInfoResult := SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, @ScreenSaverIsRunning, 0);
        if ScreenSaverIsRunning then
            begin
            SystemParametersInfoResult := SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, UINT(false), nil, SPIF_SENDWININICHANGE);
            end ;
        end ;
....
    if ScreenSaverEntryRequested then
        begin
        SystemParametersInfoResult := SystemParametersInfo (SPI_SETSCREENSAVEACTIVE, 1, nil, SPIF_SENDWININICHANGE) ;
        end ;

SystemParametersInfoResult is returning true in each case. The calls to SystemParametersInfo don't seem to have any effect. If I place the PC in SS mode by using the "Preview" button on the Control Panel Display Properties dialog, executing my code does nothing.

+3  A: 

SPI_SETSCREENSAVEACTIVE does not actually start/stop the screensaver. It is meant for actual screensavers to call to let the OS know that they are running or exiting. To start the screensaver, try sending a WM_SYSCOMMAND/SC_SCREENSAVE message to the GetDesktopWindow() window.

Remy Lebeau - TeamB
Thanks Remy. To go the other way, is there a corresponding message to kick it out of screensaver mode? At present I'm using ` Keybd_Event(VK_LCONTROL , 1, 0, 0);` Keybd_Event(VK_LCONTROL , 1, KEYEVENTF_KEYUP, 0); and it seems to work OK.
Not specifically, no. You have to either fake user input, like you are already doing, or else you would have to find the screen saver window and then send it a WM_CLOSE message. See this FAQ: http://msdn.microsoft.com/en-us/magazine/cc301462.aspx.
Remy Lebeau - TeamB