如何在程序执行期间防止屏幕保护程序和睡眠?
在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要弄乱屏幕保护程序设置,请使用 SetThreadExecutionState。这是用于通知 Windows 您的应用程序处于活动状态这一事实的 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:
, and
这不是一个坏主意,任何像样的媒体播放器都可以做到这一点...在 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.在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