使用windows api 唤醒睡眠的系统(win7)
来源:互联网 发布:如何使用淘宝冰点营销 编辑:程序博客网 时间:2024/04/29 11:50
System Wake-up Events:
Your application can restore an OnNow-capable computer that is in a sleep state to the working state by using a scheduled timer or a device event. This is known as awake-up event. Use a waitable timer object to specify the time at which the system should wake. To create the object, use theCreateWaitableTimer function. To set the timer, use theSetWaitableTimer function. The pDueTime parameter specifies when the timer will be signaled. To specify that the system should wake when the timer is signaled,set thefResume 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 and no applications indicate that the system is required via a call toSetThreadExecutionState.
- If the system wakes automatically, but the user provides new input while the event is handled, the system will not automatically return to sleep based on the unattended idle timer. Instead the system will sleep based on the system idle timer.
- If the system wakes due to user activity, the system will not automatically return to sleep based on the unattended idle timer. Instead the system will sleep based on the system idle timer.
When the system wakes automatically, the system broadcasts thePBT_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 theIsSystemResumeAutomatic function. When the system resumes 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 the sleep state, and it should prepare for user input.
Windows Server 2003, Windows XP, and Windows 2000: If an application calledSetSystemPowerState withfForce set to TRUE or the system performed a critical suspend, the system will broadcast aPBT_APMRESUMECRITICAL event after waking.
Win32 code as follows:
HANDLE hTimer = NULL;
LARGE_INTEGER liDueTime;
SYSTEMTIME st;liDueTime.QuadPart=-300000000; // 30 seconds
// Create a waitable timer.
hTimer = CreateWaitableTimer(NULL, TRUE, L"WaitableTimer");
if (NULL == hTimer)
{
printf("CreateWaitableTimer failed (%d)\n", GetLastError());
return 1;
}GetLocalTime(&st);
//printf("%d:%d:%d\n",st.wHour,st.wMinute,st.wSecond);
printf("%02d:%02d:%02d Waiting for 30 seconds...\n",st.wHour,st.wMinute,st.wSecond);// Set a timer to wait for 30 seconds.
if (!SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, TRUE))
// if (!SetWaitableTimerEx(hTimer, &liDueTime, 0, NULL, NULL, NULL,0))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
return 2;
}// Wait for the timer.
if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
printf("WaitForSingleObject failed (%d)\n", GetLastError());if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED))
{
printf("SetThreadExecutionState failed(%d)\n", GetLastError());
}
else
{
GetLocalTime(&st);
printf("%02d:%02d:%02d Timer was signaled.\n",st.wHour,st.wMinute,st.wSecond);
}
- 使用windows api 唤醒睡眠的系统(win7)
- Windows 系统关机、重启、睡眠、休眠及唤醒消息
- USB接口事件唤醒睡眠系统的分析和理解
- .巧用win7系统的睡眠方式
- 2416 睡眠唤醒的代码
- 内核的睡眠与唤醒
- 内核的睡眠与唤醒
- 线程的睡眠与唤醒
- 禁止鼠标唤醒windows 7睡眠
- windows怎么定时睡眠与唤醒
- Android睡眠唤醒机制--系统架构
- Android睡眠唤醒机制--系统架构
- Android睡眠唤醒机制--系统架构
- Android睡眠唤醒机制--系统架构
- Android睡眠唤醒机制--系统架构
- 使用select唤醒睡眠中的线程
- 设置Win7系统睡眠模式
- 设置Win7系统睡眠模式
- [Brew]CAR文件生成BAR
- linux设备驱动归纳总结(八)3设备模型的分层与面向对象
- Zend Optimizer 安装
- ArcGIS API for Silverlight开发入门(1):Getting Started
- 多线程知识点整理
- 使用windows api 唤醒睡眠的系统(win7)
- google protobuf repeated 字段二义性
- oracle 10g回收站功能
- Linux shell的一些特性
- 定制内核
- 手动执行快照
- VC中CDC与HDC的区别以及二者之间的转换
- EditText弹出软件盘时不进行全屏
- linux设备驱动归纳总结(八):4.总线热插拔