lusheng0028 发表于 2011-8-2 21:14:23

CPU和内存使都不对?大哥们帮看下,哪里不对,帮测下

#include <String.au3>
#include <GUIConstantsEx.au3>

$Form1 = GUICreate("显示统计", 200, 120, 445, 376)
$Label1 = GUICtrlCreateLabel("上传速度:", 24, 8, 55, 17)
$Label2 = GUICtrlCreateLabel("0", 88, 8, 100, 17)
$Label3 = GUICtrlCreateLabel("0", 88, 32, 100, 17)
$Label4 = GUICtrlCreateLabel("下载速度:", 24, 32, 55, 17)
$Label5 = GUICtrlCreateLabel("cpu使用率:", 24, 56, 80, 17)
$Label6 = GUICtrlCreateLabel("0", 88, 56, 100, 17)
$Label7 = GUICtrlCreateLabel("0", 108, 80, 130, 17)
$Label8 = GUICtrlCreateLabel("内存使用率:", 24, 80, 80, 17)

GUISetState(@SW_SHOW)
WinSetOnTop ($Form1,"",1)

$_IfTable=_GetIfTable()
Global $_Down=$_IfTable
Global $_UpDate=$_IfTable
Global $cpuvalus
Global $ramvalus
AdlibRegister ("_Strat_Time",500)

While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                     Exit
      EndSwitch

WEnd
Func _Strat_Time()
      $_IfTable=_GetIfTable()
                $cpuvalus=_CPU()
                $ramvalus=MemGetStats ( )
      GUICtrlSetData ($Label2, Round(($_IfTable-$_UpDate)/1024,2)& " Kb")
      GUICtrlSetData ($Label3, Round(($_IfTable-$_Down)/1024,2) & " Kb")
                GUICtrlSetData ($Label6, $cpuvalus & "%")
      GUICtrlSetData ($Label7, $ramvalus-$ramvalus & "KB")
       Global $_Down=$_IfTable
       Global $_UpDate=$_IfTable
EndFunc

Func _GetIfTable()
      $_Return=DllCall("Iphlpapi.dll","long","GetIfTable","ptr",0,"ulong*",0,"int",0)
      $_aBuffer=DllStructCreate("byte[" & $_Return & "]")
      $_Return=DllCall("Iphlpapi.dll","long","GetIfTable","ptr",DllStructGetPtr($_aBuffer),"ulong*",DllStructGetSize($_aBuffer),"int",0)
      $_Number=DllStructCreate("dword",DllStructGetPtr($_aBuffer))
      $_Number=DllStructGetData($_Number,1)
      $_MIB_IFROW="dword" & _StringRepeat(";wchar;dword;byte;dword;byte",$_Number)
      $_MIB_IFTABLE=DllStructCreate($_MIB_IFROW,DllStructGetPtr($_aBuffer))
      Dim $_Table
      For $i=2 To $_Number * 5 Step 5               
                $_Table+=DllStructGetData($_MIB_IFTABLE,$i+3,4)
                $_Table+=DllStructGetData($_MIB_IFTABLE,$i+3,10)
      Next      
      Return $_Table
EndFunc

Func _CPU()
        $wbemServices = ObjGet("winmgmts:\\.\root\cimv2")
    $wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_Processor")
    For $wbemObject In $wbemObjectSet
       $cpuvalus2=$wbemObject.LoadPercentage
   Next
    Return $cpuvalus2
EndFunc


abc... 发表于 2011-8-2 22:03:07

移动好卡,关闭无响应,试试事件模式呢。

转角遇到囜 发表于 2011-8-9 17:30:50

的确很卡呀

lxz 发表于 2011-8-10 08:37:17

好卡好卡....
页: [1]
查看完整版本: CPU和内存使都不对?大哥们帮看下,哪里不对,帮测下