Programmatically prevent Windows screensaver from starting

后端 未结 13 2057
心在旅途
心在旅途 2020-12-03 00:58

Is there a recommended way to prevent the Windows screensaver from starting? The closest thing I\'ve found is this article, but what I would really like to do is just tell

13条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 01:53

    From MSDN:

    Windows does not start the screen saver if any of the following conditions exist:

    • The active application is not a Windows-based application.
    • A CBT window is present.
    • The active application receives the WM_SYSCOMMAND message with the wParam parameter set to the SC_SCREENSAVE value, but it does not pass the message to the DefWindowProc function.

    There's a caveat though:

    Windows Vista and later: If password protection is enabled by policy, the screen saver is started regardless of what an application does with the SC_SCREENSAVE notification.

    That seems to apply even if you use the SetThreadExecutionState with ES_CONTINUOUS.

    So, if it weren't for the caveat, your choices would be:

    1. SetThreadExecutionState with ES_CONTINUOUS (as described in other answers).
    2. Put up a computer-based training window (which requires hooks).
    3. Don't let the WM_SYSCOMMAND with SC_SCREENSAVE be passed onto DefWindowProc. (Assuming you care only when your application is the active application.)
    4. Install a dongle that simulates mouse jiggle.

    The last option is nice in that it works even with the password protection policy.

提交回复
热议问题