Книга: Microsoft Windows Embedded CE 6.0 Exam Preparation Kit
Notification Interface
Notification Interface
The notification interface provides two functions that applications can use to register and deregister for power notifications through message queues, as listed in Table 3-17. It is important to note that power notifications are multicast messages, which means that Power Manager sends these notification messages only to registered processes. In this way, power management-enabled applications can seamlessly coexist on Windows Embedded CE with applications that do not implement the Power Management API.
Table 3-17 Power Management notification interface
Function | Description |
---|---|
RequestPowerNotifications | Registers an application process with Power Manager to receive power notifications. Power Manager then sends the following notification messages: |
? PBT_RESUME The system resumes from Suspend state. | |
? PBT_POWERSTATUSCHANGE The system transitions between AC power and battery power. | |
? PBT_TRANSITION The system changes to a new power state. | |
? PBT_POWERINFOCHANGE The battery status changes. This message is only valid if a battery driver is loaded. | |
StopPowerNotifications | Unregisters an application process so it no longer receives power notifications. |
The following sample code illustrates how to use power notifications:
// Size of a POWER_BROADCAST message.
DWORD cbPowerMsgSize =
sizeof POWER_BROADCAST + (MAX_PATH * sizeof TCHAR);
// Initialize a 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 ERROR;
}
// Request power notifications.
HANDLE hPowerNotifications = RequestPowerNotifications(hPowerMsgQ,
PBT_TRANSITION | PBT_RESUME | PBT_POWERINFOCHANGE);
// Wait for a power notification or for the app to exit.
while(WaitForSingleObject(hPowerMsgQ, FALSE, 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)) {
// Perform action according to the message type.
}
}
- Plug and Play Notification
- Application Interface
- IClass Power Management Interfaces
- Chapter 15. Graphical User Interfaces for Iptables
- Displaying Interface Statistics
- QueryInterface и IUnknown
- 5.1.2. The Directory Server Interface
- Command-Line Network Interface Configuration
- Laying the Foundation: The localhost Interface
- Checking for the Availability of the Loopback Interface
- Configuring the Loopback Interface Manually
- Graphic Interface Configuration of Apache