📄 powerstatus.cs
字号:
using System;
using System.Runtime.InteropServices;
namespace PInvokeLibrary
{
/// <summary>
/// Provides access to the device's power and battery status.
/// </summary>
public class PowerStatus
{
// ACLineStatus
public const byte AC_LINE_OFFLINE = 0x00;
public const byte AC_LINE_ONLINE = 0x01;
public const byte AC_LINE_BACKUP_POWER = 0x02;
public const byte AC_LINE_UNKNOWN = 0xFF;
// BatteryFlag and BackupBatteryFlag
public const byte BATTERY_FLAG_HIGH = 0x01;
public const byte BATTERY_FLAG_LOW = 0x02;
public const byte BATTERY_FLAG_CRITICAL = 0x04;
public const byte BATTERY_FLAG_CHARGING = 0x08;
public const byte BATTERY_FLAG_NO_BATTERY = 0x80;
public const byte BATTERY_FLAG_UNKNOWN = 0xFF;
// BatteryLifePercent and BackupBatteryLifePercent
public const byte BATTERY_PERCENTAGE_UNKNOWN = 0xFF;
// BatteryLifeTime, BatteryFullLifeTime, BackupBatteryLifeTime, and BackupBatteryFullLifeTime
public const uint BATTERY_LIFE_UNKNOWN = 0xFFFFFFFF;
// BatteryChemistry
public const byte BATTERY_CHEMISTRY_ALKALINE = 0x01;
public const byte BATTERY_CHEMISTRY_NICD = 0x02;
public const byte BATTERY_CHEMISTRY_NIMH = 0x03;
public const byte BATTERY_CHEMISTRY_LION = 0x04;
public const byte BATTERY_CHEMISTRY_LIPOLY = 0x05;
public const byte BATTERY_CHEMISTRY_UNKNOWN = 0xFF;
/// <summary>
/// This structure contains information about the power status of the system.
/// typedef struct _SYSTEM_POWER_STATUS_EX2
/// {
/// BYTE ACLineStatus;
/// BYTE BatteryFlag;
/// BYTE BatteryLifePercent;
/// BYTE Reserved1;
/// DWORD BatteryLifeTime;
/// DWORD BatteryFullLifeTime;
/// BYTE Reserved2;
/// BYTE BackupBatteryFlag;
/// BYTE BackupBatteryLifePercent;
/// BYTE Reserved3;
/// DWORD BackupBatteryLifeTime;
/// DWORD BackupBatteryFullLifeTime;
/// DWORD BatteryVoltage;
/// DWORD BatteryCurrent;
/// DWORD BatteryAverageCurrent;
/// DWORD BatteryAverageInterval;
/// DWORD BatterymAHourConsumed;
/// DWORD BatteryTemperature;
/// DWORD BackupBatteryVoltage;
/// BYTE BatteryChemistry;
/// } SYSTEM_POWER_STATUS_EX2, *PSYSTEM_POWER_STATUS_EX2,
/// *LPSYSTEM_POWER_STATUS_EX2;
/// </summary>
public class SYSTEM_POWER_STATUS_EX2
{
/// <summary>
/// AC power status.
/// </summary>
public byte ACLineStatus;
/// <summary>
/// Battery charge status.
/// </summary>
public byte BatteryFlag;
/// <summary>
/// Percentage of full battery charge remaining. This member can be a value
/// in the range 0 to 100, or 255 if the status is unknown. All other values
/// are reserved.
/// </summary>
public byte BatteryLifePercent;
/// <summary>
/// Reserved; set to zero.
/// </summary>
public byte Reserved1;
/// <summary>
/// Number of seconds of battery life remaining, or 0xFFFFFFFF if remaining
/// seconds are unknown.
/// </summary>
public uint BatteryLifeTime;
/// <summary>
/// Number of seconds of battery life when at full charge, or 0xFFFFFFFF if
/// full battery lifetime is unknown.
/// </summary>
public uint BatteryFullLifeTime;
/// <summary>
/// Reserved; set to zero.
/// </summary>
public byte Reserved2;
/// <summary>
/// Backup battery charge status.
/// </summary>
public byte BackupBatteryFlag;
/// <summary>
/// Percentage of full backup battery charge remaining. This value must
/// be in the range 0 to 100, or BATTERY_PERCENTAGE_UNKNOWN.
/// </summary>
public byte BackupBatteryLifePercent;
/// <summary>
/// Reserved; set to zero.
/// </summary>
public byte Reserved3;
/// <summary>
/// Number of seconds of backup battery life remaining, or
/// BATTERY_LIFE_UNKNOWN if remaining seconds are unknown.
/// </summary>
public uint BackupBatteryLifeTime;
/// <summary>
/// Number of seconds of backup battery life when at full charge, or
/// BATTERY_LIFE_UNKNOWN if full battery lifetime is unknown.
/// </summary>
public uint BackupBatteryFullLifeTime;
/// <summary>
/// Amount of battery voltage in millivolts (mV). This member can have
/// a value in the range of 0 to 65,535.
/// </summary>
public uint BatteryVoltage;
/// <summary>
/// Amount of instantaneous current drain in milliamperes (mA). This member
/// can have a value in the range of 0 to 32,767 for charge, or 0 to
///
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -