美文网首页
nim调用GetSystemPowerStatus判断笔记本电脑

nim调用GetSystemPowerStatus判断笔记本电脑

作者: 火星猎手 | 来源:发表于2017-12-01 20:30 被阅读36次

title: nim调用GetSystemPowerStatus判断笔记本电脑是否接通外接电源
tags:nim,winapi,dll


转载条件:如果你需要转载本文,你需要做到完整转载本文所有的内容,不得删改文内的作者名字与链接。否则拒绝转载。

nim调用GetSystemPowerStatus判断笔记本电脑是否接通外接电源:

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/oldwinapi

codegay
2017年12月01日 20时26分02秒

相关文章

网友评论

      本文标题:nim调用GetSystemPowerStatus判断笔记本电脑

      本文链接:https://www.haomeiwen.com/subject/imtgbxtx.html