This question already has answers here:
Prevent windows from going into sleep when my program is running?

(7个答案)



Is there a way in Qt to prohibit the computer from going to sleep?

(3个答案)


5年前关闭。




我使用Qt和Visual Studio 2015在C++中开发了一个应用程序。

我想知道如何防止我的应用程序运行时应用程序表单进入休眠状态。我的应用程序应始终在后台运行,并响应用户通过语音命令它。

当我的应用程序运行时,是否有任何措施可以防止Windows进入休眠状态?

最佳答案

SetThreadExecutionState 函数

使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示器。

在此处阅读有关API的更多信息:SetThreadExecutionState

例子:

// 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);

关于c++ - 当我的C++应用程序运行时,如何防止Windows进入休眠状态?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34836406/

10-11 22:54
查看更多