当我的C ++应用程序运行时,如何防止Windows进入睡眠状态? [英] How to prevent windows from going to sleep when my c++ application is running?

查看:706
本文介绍了当我的C ++应用程序运行时,如何防止Windows进入睡眠状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Qt和Visual Studio 2015一起使用c ++开发了一个应用程序.

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.

有什么可以防止我的应用程序运行时Windows进入睡眠状态?

Is there any to prevent windows from going to sleep when my application is running?

推荐答案

SetThreadExecutionState 函数

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

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.

在此处了解有关API的更多信息: SetThreadExecutionState

Read more about the API here: 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 ++应用程序运行时,如何防止Windows进入睡眠状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆