I develop an application in c++ with Qt and visual studio 2015.
I want to know how to prevent the application form going to sleep when my application is running. My application should be always running in background and responding to the user commanding it by voice.
Is there any to prevent windows from going to sleep when my application is running?
SetThreadExecutionState function
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.
Read more about the API here: SetThreadExecutionState
Example:
// The following sets the appropriate flags to prevent system to go into sleep mode.
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
// This clears the flags and allows the system to sleep normally.
SetThreadExecutionState(ES_CONTINUOUS);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With