[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: %x
', 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_TRANSITION
'));
if(ppb->Length) {
RETAILMSG(1,(L'SystemPowerState: %s
', ppb->SystemPowerState));
}
break;
}
case PBT_RESUME: {
RETAILMSG(1,(L'Notification: PBT_RESUME
'));
break;
}
case PBT_POWERINFOCHANGE: {
RETAILMSG(1,(L'Notification: PBT_POWERINFOCHANGE
'));
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
1. Create a WCE Application named Subproject_Shell using the Subproject Wizard. Use the Typical Hello_World Application option.
2. Before the first LoadString line, add a SignalStarted instruction.
// Initialization complete,
// call SignalStarted...
SignalStarted(_wtol(lpCmdLine));
3. Build the application.
4. Add a registry key in the subproject .reg file to launch the application at startup. Add the following lines, which create the corresponding Launch99 and Depend99 entries:
[HKEY_LOCAL_MACHINEINIT]
'Launch99'='Subproject_Shell.exe'
'Depend99'=hex:14,00,1e,00
5. Build and start the run-time image.
6. Verify that the Subproject_Shell application starts automatically.
7. Replace the reference to Explorer.exe in the Launch50 registry key with a reference to the Subproject_Shell application, as follows:
[HKEY_LOCAL_MACHINEINIT]
'Launch50'='Subproject_Shell.exe'
'Depend50'=hex:14,00,1e,00
8. Build and start the run-time image.
9. Verify that the target device runs the Subproject_Shell application in place of the standard shell, as illustrated in Figure 3-13.

Figure 3-13 Replacing the standard shell with a Subproject_Shell application