Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i prevent screen-savers and sleeps during my program execution?

In a c++ program run on Win7, is there a way to fake a mouse movement or something like that, just to keep the screen saver from starting and the system from going to sleep? I'm looking for the minimal approach and I prefer not to use .NET. Thanks, -nuun

like image 430
naor Avatar asked Sep 08 '10 07:09

naor


2 Answers

Don't mess with the screensaver settings, use SetThreadExecutionState. This is the API for informing windows on the fact that your application is active:

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.

, and

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

like image 96
Damien_The_Unbeliever Avatar answered Oct 17 '22 04:10

Damien_The_Unbeliever


That's not a bad idea, any decent media player does it... Look for SystemParametersInfo(SPI_SETSCREENSAVEACTIVE ...) function in Win32 api, it should do the trick.

like image 25
alxx Avatar answered Oct 17 '22 05:10

alxx