如果电量低于10%立即关闭软件a,关闭软件a后的1秒进行关机。
刚刚接触代码,想要的效果是用vs2019生成程序后就能达到上面所叙述的结果,请帮个忙。
以上是Windows平台。
请帮写个简单的Windows代码
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
爱看书的小沐 2022-09-06 23:55关注修改了一下再试试。
#include <Windows.h> #include <iostream> #include <tchar.h> int _tmain(int argc, _TCHAR* argv[]) { while (true) { //获取计算机的当前电量 SYSTEM_POWER_STATUS power_staus; int ret = GetSystemPowerStatus(&power_staus); int battery_percent = (int)power_staus.BatteryLifePercent; printf("%d%%\n", battery_percent); //电量小于10%,关闭程序test.exe(使用结束进程的方法) if (battery_percent <= 10) { system("TASKKILL /F /IM test.exe"); //一秒之后,执行关机操作 Sleep(1000); system("shutdown -s -f -t 0"); } //间隔1秒循环检测 Sleep(1000); } }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录