使用 WINAPI C++,当我的笔记本电脑电量达到 95% 时,我需要停止充电,我该怎么做?
尝试挖掘 winapi 文档但没有找到任何东西
您是否尝试查看电源管理 API? 这是代码片段
#include <Windows.h>
GUID currentPowerScheme;
PowerGetActiveScheme(NULL, ¤tPowerScheme);
SYSTEM_POWER_STATUS powerStatus;
GetSystemPowerStatus(&powerStatus);
ULONG batteryCapacity = powerStatus.BatteryLifePercent;
DWORD batteryThreshold = 95;
if (batteryCapacity >= batteryThreshold) {
GUID subGroup = GUID_ACDC_POWER_SOURCE;
GUID powerSetting = GUID_BATTERY_DISCHARGE_THRESHOLD;
DWORD batteryStopThreshold = batteryThreshold * 100;
POWER_SETTING_VALUE value;
value.ValueLength = sizeof(DWORD);
value.Data = &batteryStopThreshold;
PowerWriteACValueIndex(NULL, ¤tPowerScheme, &subGroup, &powerSetting, batteryStopThreshold);
}