不用HOTKEY停止,但反应有点慢.
#include <GuiListView.au3>
#include <timers.au3 >
#Region ### START Koda GUI section ### Form=
Dim $111 = -1, $aaa = 0, $Timer
$Form1 = GUICreate("Form1", 458, 360)
$ListView1 = GUICtrlCreateListView("服务器昵称 |IP/域名 |状态 |丢包情况 ", 8, 24, 440, 289)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$var = IniReadSection("Ip.ini", "服务器")
If @error Then
MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
Else
For $i = 1 To $var[0][0]
GUICtrlCreateListViewItem($var[$i][0] & "|" & $var[$i][1] & "|待测 |待测", $ListView1)
Next
EndIf
$Button1 = GUICtrlCreateButton("开始检测", 288, 320, 75, 25)
GUICtrlSetFont(-1, 9, 400, 0, "宋体")
$Button2 = GUICtrlCreateButton("停止检测", 375, 320, 75, 25)
GUICtrlSetFont(-1, 9, 400, 0, "宋体")
$Checkbox1 = GUICtrlCreateCheckbox("日志记录", 210, 325, 65, 17)
GUICtrlSetFont(-1, 9, 400, 0, "宋体")
GUISetState(@SW_SHOW, $Form1)
#EndRegion ### END Koda GUI section ###
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $Button1
$Timer = _Timer_SetTimer($Form1, 1000, 'pingla')
Case $Button2
_Timer_KillTimer($Form1, $Timer)
EndSwitch
WEnd
Func pingla($hWnd, $Msg, $iIDTimer, $dwTime)
If WinExists("错误", "发生错误,可能目标文件并非标准的INI文件.") Then
_Timer_KillTimer($Form1, $Timer)
Return
EndIf
$111 = -1
$var = IniReadSection("Ip.ini", "服务器")
If @error Then
MsgBox(4096, "错误", "发生错误,可能目标文件并非标准的INI文件.", 3)
Else
For $i = 1 To $var[0][0]
$aaa = 0
$111 = $111 + 1
$1 = Ping($var[$i][1], 250)
If @error Then
$aaa = $aaa + 1
_GUICtrlListView_AddSubItem($ListView1, $111, "第一次失败", 2)
_GUICtrlListView_AddSubItem($ListView1, $111, $aaa * 25 & " %", 3)
EndIf
$2 = Ping($var[$i][1], 250)
If @error Then
$aaa = $aaa + 1
_GUICtrlListView_AddSubItem($ListView1, $111, "第二次失败", 2)
_GUICtrlListView_AddSubItem($ListView1, $111, $aaa * 25 & " %", 3)
EndIf
$3 = Ping($var[$i][1], 250)
If @error Then
$aaa = $aaa + 1
_GUICtrlListView_AddSubItem($ListView1, $111, "第三次失败", 2)
_GUICtrlListView_AddSubItem($ListView1, $111, $aaa * 25 & " %", 3)
EndIf
$4 = Ping($var[$i][1], 250)
If @error Then
$aaa = $aaa + 1
_GUICtrlListView_AddSubItem($ListView1, $111, "第四次失败", 2)
_GUICtrlListView_AddSubItem($ListView1, $111, $aaa * 25 & " %", 3)
EndIf
$cc = ($1 + $2 + $3 + $4) / 4
If $cc = 0 Then
$cc = "ping不通"
EndIf
If $cc = 0 Then
_GUICtrlListView_AddSubItem($ListView1, $111, $cc, 2)
Else
_GUICtrlListView_AddSubItem($ListView1, $111, $cc & " MS", 2)
EndIf
_GUICtrlListView_AddSubItem($ListView1, $111, $aaa * 25 & " %", 3)
Sleep(200)
Next
EndIf
EndFunc ;==>pingla
|