欢迎光临
我们一直在努力

Windows休眠与唤醒事件

最近研究系统的休眠与唤醒,查阅到msdn网页:System Wake-up Events

如果系统自动起来(非人为点击操作),会发送PBT_APMRESUMEAUTOMATIC事件

如果系统因人为唤醒(鼠标、键盘、电源键),会先发送PBT_APMRESUMEAUTOMATIC事件,再发送PBT_APMRESUMESUSPEND事件(休眠唤醒事件),同时系统点亮屏幕。这时你的程序需要重新打开因为系统睡眠时关闭的文件。

而在PBT_APMRESUMESUSPEND中,说,只有窗口先收到 PBT_APMSUSPEND事件(开始休眠的事件)后,才会再收到它,否则只能收到 PBT_APMRESUMECRITICAL事件。

 

正文:

Your application can restore a computer that is in a sleep state to the working state by using a scheduled timer or a device event. This is known as a wake-up event. Use a waitable timer object to specify the time at which the system should wake. To create the object, use the CreateWaitableTimerfunction. To set the timer, use the SetWaitableTimer function. The pDueTime parameter specifies when the timer will be signaled. To specify that the system should wake when the timer is signaled, set the fResume parameter to TRUE.

When the system wakes automatically because of an event (other than power switch or user activity), the system automatically sets an unattended idle timer to at least 2 minutes. This timer gives applications sufficient time to call the SetThreadExecutionState function to indicate that they are busy. This time enables the system to return to the sleep state quickly after the computer is no longer required. The following criteria determine whether the system returns to the sleep state:

  • If the system wakes automatically (that is, no user activity is present), it shuts down as soon as the unattended idle timer expires, assuming that no applications have called SetThreadExecutionState to indicate that the system is required.
  • If the system wakes automatically, but the user provides new input while the event is handled, the system does not automatically return to sleep based on the unattended idle timer. Instead, the system returns to sleep based on the system idle timer.
  • If the system wakes due to user activity, the system does not automatically return to sleep based on the unattended idle timer. Instead the system returns to sleep based on the system idle timer.

When the system wakes automatically, it broadcasts the PBT_APMRESUMEAUTOMATIC event to all applications. Because the user is not present, most applications should do nothing. Event-handling applications, such as fax servers, should handle their events. To determine whether the system is in this state, call the IsSystemResumeAutomatic function. When the system wakes automatically, the display is not automatically turned on.

If the system wakes due to user activity, the system will first broadcast the PBT_APMRESUMEAUTOMATIC event followed by aPBT_APMRESUMESUSPEND event. In addition, the system will turn on the display. Your application should reopen files that it closed when the system entered sleep and prepare for user input.

赞(0)
未经允许不得转载:小明编程 » Windows休眠与唤醒事件

评论 抢沙发