Platform SDK: Hardware |
The system power status indicates whether the source of power for a computer is a system battery or AC power. For computers that use batteries, the system power status also indicates how much battery life remains and whether the battery is currently charging.
You can retrieve the system power status by using the GetSystemPowerStatus function. This function copies information about the power supply and battery status to a SYSTEM_POWER_STATUS structure. This structure indicates whether the system has a battery, and if it does, whether the battery is being used, and what percentage of the charge remains. The system broadcasts the PBT_APMPOWERSTATUSCHANGE event to all applications when the power status changes. When your application receives this event, it should call GetSystemPowerStatus again to determine what changed.
Applications and installable drivers typically use the system power status to determine whether continued operation is feasible. For example, before an application performs background operations such as compressing or paginating a file, it should call GetSystemPowerStatus to check whether the system is on batteries. As another example, an application that is beginning a lengthy operation should call GetSystemPowerStatus to check the status to determine whether enough battery power exists to complete the operation.
If power is low, an application can request user intervention or request that the system shut itself down. You can suspend system operation by using the SetSystemPowerState function. This generates a power management event that, if approved by all applications and drivers in the system, shuts down the system until the user restores power. Even if a computer uses AC power, an application that determines that the system is idle can request that the system shut itself down to save power.
Applications should also use the GetDevicePowerState function to check whether the hard disk is powered down. Applications that do not perform these checks can cause the hard disk to power up frequently, reducing any power saved by the system through power management. Instead, applications should wait until the user performs an action that causes the hard disk to power up before performing background operations. Applications should also shut down when possible, to save power and reduce noise.