绿色风's Blog
专注AutoIT(Au3)
  • 首页
  • 流●年
  • 笔●记
    • 学习随记
    • 源码示例
  • 脚●本
    • UDF(收集)
    • 工作室UDF
    • 工具●教程
    • 教程之GDI
  • 作●品
  • 下●载
  • 情怀ExcelTip
4月192017

AU3获取内存和CPU占用

作者:AOPO   发布:2017-4-19 15:33 Wednesday   分类:源码示例   阅读:15394次   评论:0条  

#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("资源监视", 341, 80, 460, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("CPU:", 15, 15, 38, 17)
$Progress1 = GUICtrlCreateProgress(45, 15, 200, 13)
$Label2 = GUICtrlCreateLabel("MEM:", 15, 45, 41, 17)
$Progress2 = GUICtrlCreateProgress(45, 45, 200, 13)
$Label3 = GUICtrlCreateLabel("", 250, 15, 76, 17)
$Label4 = GUICtrlCreateLabel("", 250, 45, 76, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $tIDLETIME, $tKERNELTIME, $tUSERTIME
$tIDLETIME = DllStructCreate('dword;dword')
$tKERNELTIME = DllStructCreate('dword;dword')
$tUSERTIME = DllStructCreate('dword;dword')

Global $S_Idle, $S_Kernel, $S_User
Global $E_Idle, $E_Kernel, $E_User

Global $i_CPU = 0

GetSystemTimes($S_Idle, $S_Kernel, $S_User)

AdlibRegister("CPUInfo", 1000)
AdlibRegister("MemInfo", 1000)

While 1
    Sleep(100)
WEnd

Func Form1Close()
    Exit
EndFunc

Func MemInfo()
    $aInfo = MemGetStats()
    If ($aInfo[0] >= 0) And ($aInfo[0] <= 100) Then
        GUICtrlSetData($Progress2, $aInfo[0])
        GUICtrlSetData($Label4, Round(($aInfo[1]-$aInfo[2])/1024/1024, 2) & "/" & Round($aInfo[1]/1024/1024, 2) & "GB") 
    EndIf
EndFunc

Func CPUInfo()
    GetSystemTimes($E_Idle, $E_Kernel, $E_User)
    $i_CPU = CPUCalc()
    If ($i_CPU >= 0) And ($i_CPU <= 100) Then
        GUICtrlSetData($Progress1, $i_CPU)
        GUICtrlSetData($Label3, $i_CPU & "%")
    EndIf
    GetSystemTimes($S_Idle, $S_Kernel, $S_User)
EndFunc

Func GetSystemTimes(ByRef $sIdle, ByRef $sKernel, ByRef $sUser)
    DllCall('kernel32.dll', 'int', 'GetSystemTimes', 'ptr', DllStructGetPtr($tIDLETIME), _
                                                     'ptr', DllStructGetPtr($tKERNELTIME), _
                                                     'ptr', DllStructGetPtr($tUSERTIME))
    $sIdle = DllStructGetData($tIDLETIME, 1)
    $sKernel = DllStructGetData($tKERNELTIME, 1)
    $sUser = DllStructGetData($tUSERTIME, 1)
EndFunc   ;==>GetSystemTimes

Func CPUCalc()
    Local $iSystemTime, $i_Total, $i_Idle, $i_Kernel, $i_User

    $i_Idle = $E_Idle - $S_Idle
    $i_Kernel = $E_Kernel - $S_Kernel
    $i_User = $E_User - $S_User

    $i_System = ($i_Kernel + $i_User)
    $i_Total = Int(($i_System - $i_Idle)/ $i_System * 100)

    ;ConsoleWrite($i_Total & @CRLF)
    Return $i_Total
EndFunc   ;==>CPUCalc```
<br />




本文固定链接: http://www.jianyiit.com/post-266.html

blogger
该日志由 AOPO 于2017-4-19 15:33 Wednesday发表在 源码示例 分类下。
版权所有:《绿色风's Blog》 → 《AU3获取内存和CPU占用》;
除特别标注,本博客很多文章均为原创. 互联分享,尊重版权,转载请以链接形式标明本文地址;
本文标签:

扫描二维码,在手机上阅读
上一篇::PC版微信多开
下一篇:AU3源码JDK环境配置

热门文章

相关文章

  • AU3打印预览源码示例
  • 根据自定义公式自动画图的强大工具
  • GDI+示例2
  • AU3真正的 修改IE 代理 即使生效·
  • Au3获取桌面图标名称与坐标
取消回复

发表评论

亲,头像对么?

40 + 98 =

提交中,请稍候……


木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!


    站点统计
    • 运行时间: 20254 天
    • 日志总数: 365 篇
    • 评论数量: 7237 条
    • 微语数量: 6 条
    • 附件总量: 388 件
  • 逝出的青春

  • 打赏"绿色风"



      扫码关注本站公众号 可搜本站内容

  • Autoit V3 脚本交流群

      常驻群1:905774875
      常驻群2:40672266


  • 链接

    • AU3中文论坛
    • Excel资料库
    • 完美者博客
    • 顺网小哥'S Blog
    • 猛牛哥的博客
    • 网吧系统下载
  • 分类

    • 流●年(66)
    • 笔●记(0)
    • 脚●本(0)
    • 作品(21)
    • 学习随记(51)
    • 源码示例(68)
    • UDF(收集)(26)
    • 工作室UDF(30)
    • 工具●教程(62)
    • 教程之GDI(24)
Copyright © 2013 绿色风's Blog. Powered by emlog. Theme by 射雕天龙. 鄂ICP备2021011689号-1 鄂公网安备42102302000078号 sitemap