c++ - 当我的 C++ 应用程序运行时,如何防止 Windows 进入休眠状态?

标签 c++ windows visual-studio qt

<分区>

我使用 Qt 和 visual studio 2015 在 c++ 中开发了一个应用程序。

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

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

最佳答案

设置线程执行状态函数

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

在此处阅读有关 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/

相关文章:

c++ - 有什么办法可以在 C++ 中输出实际的数组

c++ - 将SD卡上存储的电话号码插入短信发送AT命令Arduino

windows - 无法覆盖 Meteor absoluteUrl?

visual-studio - 有没有办法在Visual Studio中显示当前的TFS工作区?

c# - Visual Studio 包 (vsix) - 未安装 Visual Studio 的 Team City

c++ - 枚举为无符号整数

c++ - 导致非原子撕裂

c++ - 无需源代码即可调试/绕过 BSOD

python - 使用 python 编写 Ev3 窗口代码

visual-studio - 由于缺少 NuGet Microsoft.NET.Sdk.Functions 包,VS2019 无法加载项目,但也无法添加此包