title: nim调用GetSystemPowerStatus判断笔记本电脑是否接通外接电源
tags:nim,winapi,dll
---git
转载条件:若是你须要转载本文,你须要作到完整转载本文全部的内容,不得删改文内的做者名字与连接。不然拒绝转载。github
nim调用GetSystemPowerStatus判断笔记本电脑是否接通外接电源:api
type SYSTEM_POWER_STATUS* {.final, pure.} = object ACLineStatus*: int8 BatteryFlag*: int8 BatteryLifePercent*: int8 Reserved1*: int8 BatteryLifeTime*: int32 BatteryFullLifeTime*: int32 var test:SYSTEM_POWER_STATUS proc getPowerStatus*(stat:var SYSTEM_POWER_STATUS):int {.stdcall, dynlib:"kernel32", importc:"GetSystemPowerStatus", discardable.} test.getPowerStatus echo test echo "电池电量:",test.BatteryLifePercent if test.ACLineStatus == 0: echo "笔记本,断电了" elif test.ACLineStatus == 1: echo "笔记本,接通外接电源中" else: echo "我以为我多是运行在一台台式电脑上了。"
代码抄自:
https://github.com/nim-lang/oldwinapicode
codegay
2017年12月01日 20时26分02秒get