本帖最后由 codegay 于 2017-12-1 20:08 编辑
我也试着用nim写了一个- 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 "我觉得我可能是运行在一台台式电脑上了。"
复制代码
- 输出:
- (ACLineStatus: 1, BatteryFlag: 1, BatteryLifePercent: 99, Reserved1: 0, BatteryLifeTime: -1, BatteryFullLifeTime: -1)
- 电池电量:99
- 笔记本,接通外接电源中
复制代码
|