how do i prevent screen-savers and sleeps during my program execution?(如何在程序执行期间防止屏幕保护程序和睡眠?)
问题描述
在 Win7 上运行的 c++ 程序中,有没有办法伪造鼠标移动或类似的东西,只是为了防止屏幕保护程序启动和系统进入睡眠状态?我正在寻找最小的方法,我不喜欢使用 .NET.谢谢,-nuun
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
推荐答案
不要乱动屏保设置,使用SetThreadExecutionState.这是用于通知窗口您的应用程序处于活动状态的 API:
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.
,和
多媒体应用,例如视频播放器和演示应用程序,必须使用 ES_DISPLAY_REQUIRED 当他们长时间显示视频无需用户输入
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
这篇关于如何在程序执行期间防止屏幕保护程序和睡眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在程序执行期间防止屏幕保护程序和睡眠?


基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01