-1

I must suppress (not disable) the window screensaver while a long machine-process is runnning.

Is simulate a little mouse movement with SendInput(..) the right way?

Tom Tom
  • 1,127
  • 11
  • 25

1 Answers1

1

No, it is not.

On XP and later, use SetThreadExecutionState() instead:

Enables an application to inform the system that it is in use, thereby preventing the system from entering sleep or turning off the display while the application is running.

...

Multimedia applications, such as video players and presentation applications, must use ES_DISPLAY_REQUIRED when they display video for long periods of time without user input.

Despite what the documentation says ("This function does not stop the screen saver from executing"), this DOES stop the screensaver.

On earlier versions of Windows, you can handle the WM_SYSCOMMAND message instead. When the wParam is set to SC_SCREENSAVE, if you don't pass the message to DefWindowProc(), the screensaver will not be run, unless the screensaver is password protected, in which case it is run regardless of what happens to the WM_SYSCOMMAND message:

If password protection is enabled by policy, the screen saver is started regardless of what an application does with the SC_SCREENSAVE notification— even if fails to pass it to DefWindowProc.

Another option is to use SystemParametersInfo() to set SPI_SETSCREENSAVEACTIVE to TRUE so Windows thinks a screensaver is already running so it won't start the default screensaver.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770