Stop system entering 'standby'

徘徊边缘 提交于 2019-12-10 09:30:04

问题


How can i stop the host machine entering standby mode while my application is running?

Is there any win32 api call to do this?


回答1:


There are two APIs, depending on what version of Windows.

XP,2000, 2003:

http://msdn.microsoft.com/en-us/library/aa373247(VS.85).aspx

Respond to PBT_APMQUERYSUSPEND.

Vista, 2008:

http://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx

There could be many valid reasons to prevent the computer from going to sleep. For example, watching a video, playing music, compiling a long running build, downloading large files, etc.




回答2:


This article http://www.codeguru.com/cpp/w-p/system/messagehandling/article.php/c6907 provides a demo of how to do this from C++ (thought he article is framed as if you want to do it from Java, and provides a Java wrapper).

The actual code in in a zip file at http://www.codeguru.com/dbfiles/get_file/standbydetectdemo_src.zip?id=6907&lbl=STANDBYDETECTDEMO_SRC_ZIP&ds=20040406 and the C++ part of it is under com/ha/common/windows/standbydetector.

Hopefully it will give you enough of a direction to get started.



来源:https://stackoverflow.com/questions/56046/stop-system-entering-standby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!