找回密码
 加入
搜索
查看: 2238|回复: 1

[AU3基础] 如何停止正在运行的语句。

[复制链接]
发表于 2011-2-20 20:01:49 | 显示全部楼层 |阅读模式
点停止没有反应,如何让它停止。。
#NoTrayIcon

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <Array.au3>
Opt("WinTitleMatchMode", 2)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("ping工具", 404, 400, 199, 120)
$Label1 = GUICtrlCreateLabel("WWW/IP:", 4, 9, 39, 17)
$Input1 = GUICtrlCreateInput("www.baidu.com", 45, 7, 280, 18, $ES_NOHIDESEL, $WS_EX_STATICEDGE)
GUICtrlSetBkColor($Input1, 0xffffff)
GUICtrlSetColor($Input1, 0x000000)
GUICtrlSetFont(-1, 11)
$Label2 = GUICtrlCreateLabel("超时:", 330, 10, 30, 17)
$Input2 = GUICtrlCreateInput("1000", 360, 7, 40, 18, BitOR($ES_NUMBER, $ES_NOHIDESEL), $WS_EX_STATICEDGE)
GUICtrlSetBkColor($Input2, 0xffffff)
GUICtrlSetColor($Input2, 0x000000)
GUICtrlSetFont(-1, 11)

$Label5 = GUICtrlCreateLabel("间隔:", 10, 33, 40, 20)
$Input3 = GUICtrlCreateInput("1", 40, 30, 20, 17, $ES_NOHIDESEL, $WS_EX_STATICEDGE)
GUICtrlSetBkColor($Input3, 0xffffff)
GUICtrlSetColor($Input3, 0x000000)
GUICtrlSetFont(-1, 11)
$Label6 = GUICtrlCreateLabel("秒", 65, 33, 20, 20)
$Checkbox1 = GUICtrlCreateCheckbox("循环", 85, 30, 50, 20)
$Checkbox2 = GUICtrlCreateCheckbox("解析", 135, 30, 50, 20)
$Checkbox3 = GUICtrlCreateCheckbox("输出日志(ping.txt)", 185, 30, 125, 20)

; $Label3 = GUICtrlCreateLabel("毫秒", 225, 45, 28, 17)
$Button1 = GUICtrlCreateButton("开始", 320, 30, 35, 20, $BS_DEFPUSHBUTTON)
$Button2 = GUICtrlCreateButton("停止", 361, 30, 35, 20)

$Group1 = GUICtrlCreateGroup("Ping 详细信息", 2, 50, 400, 327, $SS_SUNKEN)
$Edit1 = GUICtrlCreateEdit("等待用户命令...", 5, 67, 392, 305, BitOR($WS_VSCROLL, $ES_NOHIDESEL, $ES_AUTOVSCROLL), $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 10)
GUICtrlSetBkColor($Edit1, 0xffffff)
GUICtrlSetColor($Edit1, 0x000000)

$Button3 = GUICtrlCreateButton("清屏", 360, 379, 40, 20)
$Label4 = GUICtrlCreateLabel(" ping工具",382, 223, 16, $SS_SUNKEN)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Select
                Case $nMsg = $GUI_EVENT_CLOSE
                        Exit
                Case $nMsg = $Button1
                        _Myping()
                Case $nMsg = $Button2
                        ProcessClose("ping")
                Case $nMsg = $Button3
                        GUICtrlSetData($Edit1, "")
        EndSelect
WEnd
Func _Myping()
        Local $Address[11], $Pings[11]
        $add = GUICtrlRead($Input1)
        If StringLen($add) Then
                If StringRegExp($add, '[\da-zA-Z./]') = 0 Then
                        GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "错误: 主机地址格式错误.  多个地址用 " / " 隔开. ")
                        Return
                EndIf
        EndIf
        $Address = StringSplit($add, "/")
        If $Address[0] > 10 Then
                MsgBox(0, "提示", "请不要同时ping多台主机.")
                Return
        EndIf
        $aninary = GUICtrlRead($Input2)
        $delay = GUICtrlRead($Input3) * 1000
        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                While 1
                        For $i = 1 To $Address[0] Step +1
                                Select
                                        Case $Address[$i] = ""
                                                GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "错误: 主机地址不能为空. ")
                                                Return
                                        Case StringInStr($Address[$i], ".") = 0
                                                GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "错误: 无效的主机地址. ")
                                                Return
                                        Case $Address[$i]
                                                $Pings[$i] = Ping($Address[$i], GUICtrlRead($Input2))
                                                GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & @CRLF & "主机 " & $Address[$i] _
                                                                 & " 的Ping值为: " & $Pings[$i] & "毫秒(ms).")
                                EndSelect
                                ControlSend("Myping", "", "[CLASS:Edit; INSTANCE:4]", "{end}")
                                Sleep($delay)
                        Next
                WEnd
        Else

                For $i = 1 To $Address[0] Step +1
                        Local $T = 0, $F = 0
                        For $s = 1 To 4 Step +1
                                TCPStartup()
                                $ip = "(" & TCPNameToIP($Address[$i]) & ")"
                                TCPShutdown()
                                If $s = 1 Then GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "正在Ping: " & $Address[$i] & $ip & @CRLF _
                                                 & "响应超时:" & $aninary & "毫秒 " & "开始于:" & @YEAR & "/" & @MON & "/" & @MDAY & " " & _
                                                @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)
                                Select
                                        Case $Address[$i] = ""
                                                GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "错误: 主机地址不能为空. ")
                                                Return
                                        Case StringInStr($Address[$i], ".") = 0
                                                GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "错误: 无效的主机地址. ")
                                                Return
                                        Case $Address[$i]
                                                $Pings[$i] = Ping($Address[$i], $aninary)
                                                If $Pings[$i] Then
                                                        GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "主机 " & $Address[$i] & " 的Ping值为: " & $Pings[$i] & "毫秒(ms).")
                                                        $T = $T + 1
                                                Else
                                                        GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & " ")
                                                        $F = $F + 1
                                                EndIf
                                EndSelect
                                Sleep($delay)
                        Next
                        If $F <> 0 And $T <> 0 Then
                                $bf = Round($F / $T, 2) & "%"
                        Else
                                If $F = 0 Then $bf = "0%"
                                If $T = 0 Then $bf = "100%"
                        EndIf
                        GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & @CRLF & $Address[$i] & " 的统计信息_" & @YEAR & "/" & @MON & "/" & @MDAY & " " & _
                                        @HOUR & ":" & @MIN & ":" & @SEC & @CRLF & " 统计: 已发送: " & $s - 1 & " 已接收: " & $T & " 丢失: " & $F & _
                                        " <丢包率:" & $bf & ">" & @CRLF)
                        ControlSend("ping工具", "", "[CLASS:Edit; INSTANCE:4]", "{end}")
                Next
        EndIf
EndFunc
发表于 2011-2-21 12:02:02 | 显示全部楼层
我不知道热键行不?

HotKeySet ( "热键" [, "函数名"] )
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 09:22 , Processed in 0.084521 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表