如何在程序执行期间防止屏幕保护程序和睡眠?

发布于 2024-09-18 08:36:16 字数 97 浏览 1 评论 0原文

在Win7上运行的C++程序中,有没有办法伪造鼠标移动或类似的东西,只是为了防止屏幕保护程序启动和系统进入睡眠状态?我正在寻找最小的方法,并且我不喜欢使用.NET。 谢谢, -努恩

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦亿 2024-09-25 08:36:16

不要弄乱屏幕保护程序设置,请使用 SetThreadExecutionState。这是用于通知 Windows 您的应用程序处于活动状态这一事实的 API:

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

, 和

多媒体应用程序,例如视频
播放器和演示应用程序,
必须使用 ES_DISPLAY_REQUIRED 时
长时间显示视频
无需用户输入

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.

, and

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

不念旧人 2024-09-25 08:36:16

这不是一个坏主意,任何像样的媒体播放器都可以做到这一点...在 Win32 api 中查找 SystemParametersInfo(SPI_SETSCREENSAVEACTIVE ...) 函数,它应该可以解决问题。

That's not a bad idea, any decent media player does it... Look for SystemParametersInfo(SPI_SETSCREENSAVEACTIVE ...) function in Win32 api, it should do the trick.

黯然 2024-09-25 08:36:16

在Windows启动屏幕保护程序之前,它会在WM_SYSCOMMAND消息中向应用程序发送SC_SCREENSAVE通知。如果应用程序想要阻止屏幕保护程序启动,则应将“handled”标志设置为 true 并在消息处理期间返回零。还有 SC_MONITORPOWER 可以防止显示器进入低功耗状态。

https://learn.microsoft.com/en-us/ windows/desktop/menurc/wm-syscommand

Before Windows starts screen-saver, it sends SC_SCREENSAVE notification in WM_SYSCOMMAND message to applications. If application wants to prevent screen-saver from starting, it should set "handled" flag to true and return zero during message processing. There is also SC_MONITORPOWER to prevent display from going to low power state.

https://learn.microsoft.com/en-us/windows/desktop/menurc/wm-syscommand

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文