英文:
C++ WINAPI Charging
问题
我需要在我的笔记本电脑充电达到95%时停止充电,使用WinAPI C++,我该如何做到这一点?
尝试浏览WinAPI文档,但未找到任何信息。
英文:
I need to stop charging my laptop when it reaches 95% using WINAPI C++ how can I do that?
Tried digging through the winapi documentation but didn't find anything
答案1
得分: 0
你试过查看电源管理 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);
}
英文:
Did you try looking at the power management API?
Here is the code snippet:
#include <Windows.h>
GUID currentPowerScheme;
PowerGetActiveScheme(NULL, &currentPowerScheme);
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, &currentPowerScheme, &subGroup, &powerSetting, batteryStopThreshold);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论