回复 7# pusofalse
[code]
Const $tagMIB_IFROW = "wchar Name[256];dword Index;dword Type;dword Mtu;dword Speed;dword PhysicalAddrLen;byte PhysicalAddr[8];dword AdminStatus;dword OperStatus;dword LastChange;dword InOctets;dword InUcastPkts;dword InNUcastPkts;dword InDiscards;dword InErrors;dword InUnknownProtos;dword OutOctets;dword OutUcastPkts;dword OutNUcastPkts;dword OutDiscards;dword OutErros;dword OutQLen;dword DescrLen;char Descr[256]"
Local $aIfEntry = _EnumIfEntries()
Local $iPrevInOctets = $aIfEntry[2][8]
Local $iPrevOuOctets = $aIfEntry[2][9]
Local $iCurrOctets, $iCurrOuOctets, $iCurrInOctets, $iIfIndex
For $i = 1 To $aIfEntry[0][0]
If ($aIfEntry[$i][3] = 6) Then
$iIfIndex = $aIfEntry[$i][2]
ExitLoop
EndIf
Next
If ($iIfIndex = 0) Then Exit
HotKeySet("{esc}", "_Quit")
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
Global $IDLETIME, $KERNELTIME, $USERTIME
Global $StartIdle, $StartKernel, $StartUser
Global $EndIdle, $EndKernel, $EndUser
Global $Timer
$hGUI = GUICreate("CPUmon", 400, 300, -1, -1, 0x80800000);, $WS_EX_TOPMOST)
GUISetBkColor(0x000000)
GUICtrlCreateGraphic(0, 0, 400, 300)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x008040)
For $y = 25 To 375 Step 25
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $y)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, 400, $y)
Next
For $x = 25 To 575 Step 25
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $x, 0)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $x, 300)
Next
$gr = GUICtrlCreateGraphic(0, 50, 400, 300)
$lb = GUICtrlCreateLabel("测试数据", 300, 200, 25, 25)
GUICtrlSetColor(-1, 0x00FF00)
GUISetState()
GUICtrlSetGraphic($gr, $GUI_GR_COLOR, 0x00FF00)
$x = 0
$y = 0
$dx = 400
$dy = 300
GUICtrlSetGraphic($gr, $GUI_GR_MOVE, $dx, $dy)
;绘图示例
;~ ;$Y | ,$x _
While 1
$dx += 10 ;X轴两个点之间的间隔
$dy = Random(50, 250, 1) ;产生随机数,在1-100之间都行
GUICtrlSetGraphic($gr, $GUI_GR_LINE, $dx, $dy) ;$dx $dy
GUICtrlSetGraphic($gr, $GUI_GR_REFRESH)
$x -= 2
GUICtrlSetPos($gr, $x, $y)
GUICtrlSetPos($lb, $x + 300, $y)
Sleep(100)
WEnd
While 1
$aIfEntry = _EnumIfEntries()
$iCurrInOctets = $aIfEntry[$iIfIndex][8] - $iPrevInOctets
$iCurrOuOctets = $aIfEntry[$iIfIndex][9] - $iPrevOuOctets
$iPrevInOctets = $aIfEntry[$iIfIndex][8]
$iPrevOuOctets = $aIfEntry[$iIfIndex][9]
$iCurrOctets = $iCurrInOctets + $iCurrOuOctets
$dx += 10 ;X轴两个点之间的间隔
$dy = Round($iCurrOctets / $aIfEntry[$iIfIndex][4] * 1000, 0) ;计算
ToolTip("检测网络使用率: " & $dy & " %", 10, 10)
;绘图开始
GUICtrlSetGraphic($gr, $GUI_GR_LINE, $dx, $dy) ;$dx $dy
GUICtrlSetGraphic($gr, $GUI_GR_REFRESH)
$x -= 2
GUICtrlSetPos($gr, $x, $y)
GUICtrlSetPos($lb, $x + 300, $y)
;绘图结束
$aIfEntry = 0
Sleep(500)
WEnd
Func _Quit()
Exit
EndFunc ;==>_Quit
Func _EnumIfEntries()
Local $iResult, $tBuffer, $pBuffer, $tIfEntry, $tCount, $aResult[1][10]
$iResult = DllCall("iphlpapi.dll", "dword", "GetIfTable", "ptr", 0, "ulong*", 0, "int", 1)
$tBuffer = DllStructCreate("ubyte Binary[" & $iResult[2] & "]")
$pBuffer = DllStructGetPtr($tBuffer, "Binary")
$iResult = DllCall("iphlpapi.dll", "dword", "GetIfTable", "ptr", $pBuffer, _
"ulong*", $iResult[2], "int", 1)
$tCount = DllStructCreate("ulong NumberofEntries", $pBuffer)
$aResult[0][0] = DllStructGetData($tCount, "NumberofEntries")
ReDim $aResult[$aResult[0][0] + 1][10]
$pBuffer += 4
For $i = 1 To $aResult[0][0]
$tIfEntry = DllStructCreate($tagMIB_IFROW, $pBuffer)
$pBuffer += DllStructGetSize($tIfEntry)
$aResult[$i][0] = DllStructGetData($tIfEntry, "Name")
$aResult[$i][1] = DllStructGetData($tIfEntry, "Descr")
$aResult[$i][2] = DllStructGetData($tIfEntry, "Index")
$aResult[$i][3] = DllStructGetData($tIfEntry, "Type")
$aResult[$i][4] = DllStructGetData($tIfEntry, "Speed")
$aResult[$i][5] = DllStructGetData($tIfEntry, "PhysicalAddr")
$aResult[$i][6] = DllStructGetData($tIfEntry, "AdminStatus")
$aResult[$i][7] = DllStructGetData($tIfEntry, "OperStatus")
$aResult[$i][8] = DllStructGetData($tIfEntry, "InOctets")
$aResult[$i][9] = DllStructGetData($tIfEntry, "OutOctets")
$tIfEntry = 0
Next
$tBuffer = 0
Return SetError($iResult[0], 0, $aResult)
EndFunc ;==>_EnumIfEntries
[code]
绘图。调整 $dy 在 100以内,就能按比例显示了。超过100就超过了绘图控件的顶端。
第一个循环是演示,第二个循环是显示网络连接使用率 |