您的位置:首页 > 编程语言 > C语言/C++

vc++如何获取笔记本电源电量信息以及充电状态

2017-06-26 17:30 423 查看
http://bbs.csdn.net/topics/391051005

从论坛摘抄

GetSystemPowerStatus  获取电池总容量跟剩余容量的API函数

GetSystemPowerStatus Function  

发送反馈
Retrieves the power status of the system. The status indicates whether the system is running on AC or DC power, whether the battery is currently charging, and how much battery life remains.

Syntax
C++以带有颜色区分的格式查看复制到剪贴板打印BOOL WINAPI GetSystemPowerStatus(
  __out  LPSYSTEM_POWER_STATUS lpSystemPowerStatus
);
BOOL WINAPI GetSystemPowerStatus(
  __out  LPSYSTEM_POWER_STATUS lpSystemPowerStatus
);

Parameters
lpSystemPowerStatus [out] 
A pointer to a SYSTEM_POWER_STATUS structure that receives status information. 

Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError. 

Remarks
To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0400 or later. For more information, see Using the Windows Headers. 

Requirements
Minimum supported client Windows 2000 Professional 
Minimum supported server Windows 2000 Server 
Header Winbase.h (include Windows.h) 
Library Kernel32.lib 
DLL Kernel32.dll 

See Also 
System Power Status
Power Management Functions
SYSTEM_POWER_STATUS
 

 

Send comments about this topic to Microsoft

Build date: 12/13/2009

© 2011 Microsoft Corporation。保留所有权利

发送反馈 (请阅读我们的 Visual Studio 反馈策略)
SYSTEM_POWER_STATUS Structure  

发送反馈
Contains information about the power status of the system.

Syntax
C++以带有颜色区分的格式查看复制到剪贴板打印typedef struct _SYSTEM_POWER_STATUS {
  BYTE  ACLineStatus;
  BYTE  BatteryFlag;
  BYTE  BatteryLifePercent;
  BYTE  Reserved1;
  DWORD BatteryLifeTime;
  DWORD BatteryFullLifeTime;
} SYSTEM_POWER_STATUS, *LPSYSTEM_POWER_STATUS;
typedef struct _SYSTEM_POWER_STATUS {
  BYTE  ACLineStatus;
  BYTE  BatteryFlag;
  BYTE  BatteryLifePercent;
  BYTE  Reserved1;
  DWORD BatteryLifeTime;
  DWORD BatteryFullLifeTime;
} SYSTEM_POWER_STATUS, *LPSYSTEM_POWER_STATUS;

Members
ACLineStatus
The AC power status. This member can be one of the following values. 

Value Meaning 
0 Offline
 
1 Online
 
255 Unknown status
 

 

BatteryFlag
The battery charge status. This member can contain one or more of the following flags. 

Value Meaning 
1 High—the battery capacity is at more than 66 percent
 
2 Low—the battery capacity is at less than 33 percent
 
4 Critical—the battery capacity is at less than five percent
 
8 Charging
 
128 No system battery
 
255 Unknown status—unable to read the battery flag information
 

 

The value is zero if the battery is not being charged and the battery capacity is between low and high.

BatteryLifePercent
The percentage of full battery charge remaining. This member can be a value in the range 0 to 100, or 255 if status is unknown.

Reserved1
Reserved; must be zero.

BatteryLifeTime
The number of seconds of battery life remaining, or –1 if remaining seconds are unknown.

BatteryFullLifeTime
The number of seconds of battery life when at full charge, or –1 if full battery lifetime is unknown.

Remarks
The system is only capable of estimating BatteryFullLifeTime based on calculations on BatteryLifeTime and BatteryLifePercent. Without smart battery subsystems, this value may not be accurate enough to be useful. 

Requirements
Minimum supported client Windows 2000 Professional 
Minimum supported server Windows 2000 Server 
Header Winbase.h (include Windows.h) 

See Also 
GetSystemPowerStatus
PBT_APMPOWERSTATUSCHANGE
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: