Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Deactivate Screensaver/Power States while game is running

  1. #1

    Deactivate Screensaver/Power States while game is running

    I've coded a simple dll in delphi in order to deactivate the screensaver when my game is running.
    I can use the function _enableSSaver to activate it back when I am done, but in case of a ctrl+alt+del or a crash the screensaver won't go back to normal.
    I've seen there are some tags initialization/finalization but I don't know how to use them. Is there a way to make it that the screensaver is always enabled when the dll is unloaded (freed)?

    Here is my code:

    [pascal]library screenhndl;

    uses
    Windows,
    Messages,
    SysUtils;

    function _disableSSaver : pchar; stdcall;
    begin
    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,0,0,0 );
    SystemParametersInfo(SPI_SETPOWEROFFACTIVE,0,0,0);
    SystemParametersInfo(SPI_SETLOWPOWERACTIVE,0,0,0);
    end;

    function _enableSSaver : pchar; stdcall;
    begin
    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,0,0 );
    SystemParametersInfo(SPI_SETPOWEROFFACTIVE,1,0,0);
    SystemParametersInfo(SPI_SETLOWPOWERACTIVE,1,0,0);
    end;


    exports _disableSSaver;
    exports _enableSSaver;
    begin end.[/pascal]

  2. #2

    Deactivate Screensaver/Power States while game is running

    I seem to recall reading somewhere that calling changeresolution with the flag cds_fullscreen will block screensavers and power options, eg. sleep, hibernate, etc.
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Deactivate Screensaver/Power States while game is running

    Hey, not bad. Though I think a better solution may be to have the game 'kick' the system's input queue every so often instead.

    What happens when you simply set and reset these values instead of 'permanently' setting them at the start and reseting them at the end of your game? Would that result in such a 'kick' as I'm referring to?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #4

    Deactivate Screensaver/Power States while game is running

    I hope you test the settings before you use your DLL calls... Otherwise, the player will have the screensaver and those other stuff enabled after he played your game, even if it was disabled before

    Greetings,
    Dirk
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  5. #5

    Deactivate Screensaver/Power States while game is running

    I hope you test the settings before you use your DLL calls... Otherwise, the player will have the screensaver and those other stuff enabled after he played your game, even if it was disabled before
    ..or the Screensaver will be disabled if the game crashes and doesn't clean up properly.

    Probably be better to find a less destructive way of preventing the screensaver from kicking in.

  6. #6

    Deactivate Screensaver/Power States while game is running

    I seem to recall reading somewhere that calling changeresolution with the flag cds_fullscreen will block screensavers and power options, eg. sleep, hibernate, etc.
    You are talking about exclusive mode?

    The fact is that with the [pascal]initialization[/pascal] and [pascal]finalization[/pascal] tags you can automatically unload a dll and its functions even when the game has been forced quit (ctrl+alt+del) or crashed.

    But I don't know how to use them. Anyone that can apply it to the code above.

  7. #7

    Deactivate Screensaver/Power States while game is running

    no actually I was talking about ChangeDisplaySettings
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  8. #8

    Deactivate Screensaver/Power States while game is running

    procedure WMSysCommand(var Msg : TWMSysCommand); message WM_SYSCOMMAND;

    [pascal]
    // SWITCH OFF THE SCREENSAVER AND THE MONITOR POWER SAVER IF THEY TRY TO CUT IN
    procedure TForm1.WMSysCommand(var Msg : TWMSysCommand);
    begin
    //catch the message and turn it off
    if (Msg.CmdType = SC_MONITORPOWER) or (Msg.CmdType = SC_SCREENSAVE) then
    begin
    Msg.Result := -1;
    end
    else
    inherited;///Otherwise do whatever is supposed to be done
    end;
    [/pascal]


    That does the trick
    The views expressed on this programme are bloody good ones. - Fred Dagg

  9. #9

    Deactivate Screensaver/Power States while game is running

    There is also another way:
    [pascal]
    type
    EXECUTION_STATE = DWORD;
    const
    ES_SYSTEM_REQUIRED = DWORD($00000001);
    ES_DISPLAY_REQUIRED = DWORD($00000002);
    ES_USER_PRESENT = DWORD($00000004);
    ES_CONTINUOUS = DWORD($80000000);

    function SetThreadExecutionState(esFlags: EXECUTION_STATE): EXECUTION_STATE; stdcall; external kernel32;

    ......
    SetThreadExecutionState(ES_DISPLAY_REQUIRED or ES_CONTINUOUS); // this will fix current state and disable screensaver[/pascal]
    There are only 10 types of people in this world; those who understand binary and those who don't.

  10. #10

    Deactivate Screensaver/Power States while game is running

    Will it be compatible with most versions of the Windows including Vista?

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •