Книга: Microsoft Windows Embedded CE 6.0 Exam Preparation Kit
? Enable Power Management Notification Messages
? Enable Power Management Notification Messages
1. Continue to use the HelloWorld application in Visual Studio.
2. Generate power-management notifications in more frequent intervals by going into the subproject registry settings and setting the registry entry for the UserIdle timeout in AC power mode (ACUserIdle) to five seconds:
[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlPowerTimeouts]
"ACUserIdle"=dword:5 ; in seconds
3. In the ThreadProc function, create a message queue object:
// Size of a POWER_BROADCAST message.
DWORD cbPowerMsgSize =
sizeof POWER_BROADCAST + (MAX_PATH * sizeof TCHAR);
// Initialize our MSGQUEUEOPTIONS structure.
MSGQUEUEOPTIONS mqo;
mqo.dwSize = sizeof(MSGQUEUEOPTIONS);
mqo.dwFlags = MSGQUEUE_NOPRECOMMIT;
mqo.dwMaxMessages = 4;
mqo.cbMaxMessage = cbPowerMsgSize;
mqo.bReadAccess = TRUE;
//Create a message queue to receive power notifications.
HANDLE hPowerMsgQ = CreateMsgQueue(NULL, &mqo);
if (NULL == hPowerMsgQ) {
RETAILMSG(1, (L"CreateMsgQueue failed: %xn", GetLastError()));
return -1;
}
4. Request to receive notifications from Power Manager and check the received messages:
// Request power notifications
HANDLE hPowerNotifications = RequestPowerNotifications(hPowerMsgQ,
PBT_TRANSITION | PBT_RESUME | PBT_POWERINFOCHANGE);
DWORD dwCounter = 20;
// Wait for a power notification or for the app to exit
while(dwCounter-- &&
WaitForSinglObject(hPowerMsgQ, INFINITE) == WAIT_OBJECT_0) {
DWORD cbRead;
DWORD dwFlags;
POWER_BROADCAST *ppb =
(POWER_BROADCAST*) new BYTE[cbPowerMsgSize];
// loop through in case there is more than 1 msg.
while(ReadMsgQueue(hPowerMsgQ, ppb, cbPowerMsgSize,
&cbRead, 0, &dwFlags)) {
switch(ppb->Message) {
case PBT_TRANSITION: {
RETAILMSG(1,(L"Notification: PBT_TRANSITIONn"));
if(ppb->Length) {
RETAILMSG(1,(L"SystemPowerState: %sn", ppb->SystemPowerState));
}
break;
}
case PBT_RESUME: {
RETAILMSG(1,(L"Notification: PBT_RESUMEn"));
break;
}
case PBT_POWERINFOCHANGE: {
RETAILMSG(1,(L"Notification: PBT_POWERINFOCHANGEn"));
break;
}
default:
break;
}
}
delete[] ppb;
}
5. Build the application and rebuild the run-time image.
6. Start the run-time image.
7. You generate user activity by moving the mouse cursor. After five seconds of inactivity, Power Manager should notify the application, as illustrated in Figure 3-12.
Figure 3-12 Received Power Management notifications
- ? Enable Kiosk Mode
- Power Management
- За пределами PowerPoint
- Testing Wdm2 Power Capabilities
- Глава 1. POWERPOINT – ЗЛО?
- 8.4.2. Sending and Receiving Messages
- CHAPTER 17 Apache Web Server Management
- Group Management Tools
- User Management Tools
- Graphical Process and System Management Tools
- Using ssh-keygen to Enable Key-Based Logins
- Using the C Programming Project Management Tools Provided with Fedora Linux