找回密码
 加入
搜索
查看: 1848|回复: 2

[网络通信] 在GUI里循环PING如何实现(已解决)

[复制链接]
发表于 2017-1-7 10:08:19 | 显示全部楼层 |阅读模式
本帖最后由 xzh531 于 2017-1-10 08:44 编辑

我要实现如下功能,就是经验少,不知道怎么处理,求大神给分享几个方法,谢谢

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 307, 182, -1, -1)
$Label1 = GUICtrlCreateLabel("延时   MS", 80, 20, 56, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$button1 = GUICtrlCreateButton("开始", 20, 100, 50, 25)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$button2 = GUICtrlCreateButton("停止", 100, 100, 50, 25)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $button1 ;开始循环PING
                        chk()
                Case $button2 ;停止PING
        EndSwitch
WEnd

Func chk()
        While 1
                $p = Ping("192.168.6.1", 400)
                If Not @error Then
                        GUICtrlSetState($Label1, "延时   " & $p & "MS")
                EndIf
                Sleep(3000)
        WEnd
EndFunc   ;==>chk
发表于 2017-1-7 11:41:20 | 显示全部楼层
本帖最后由 q410225 于 2017-1-7 11:47 编辑


#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 307, 182, -1, -1)
$Label1 = GUICtrlCreateLabel("延时   MS", 80, 20, 56, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$button1 = GUICtrlCreateButton("开始", 20, 100, 50, 25)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$button2 = GUICtrlCreateButton("停止", 100, 100, 50, 25)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $button1 ;开始循环PING
                        AdlibRegister(chk,2000)
                        Case $button2 ;停止PING
                                 AdlibUnRegister(chk)
                                 GUICtrlSetData($Label1, "延时---MS")
        EndSwitch
WEnd

Func chk()  
              GUICtrlSetData($Label1, "延时---MS")
                  Sleep(500)
                        $p = Ping("192.168.6.1", 400)
                        If $p Then
                        GUICtrlSetData($Label1, "延时"&$p&"MS")

                        EndIf
EndFunc   ;==>chk
发表于 2017-1-8 11:26:55 | 显示全部楼层
本帖最后由 xzf680 于 2017-1-8 11:30 编辑

学习下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 19:19 , Processed in 0.083287 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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