找回密码
 加入
搜索
查看: 8669|回复: 12

[AU3基础] [已解决]自己刚写了一个网络服务器监控程序,点击开始以后,别的按钮没反应

  [复制链接]
发表于 2013-1-31 09:19:17 | 显示全部楼层 |阅读模式
本帖最后由 w393791998 于 2013-1-31 09:59 编辑

点击开始按钮后,选择窗口关闭 或者停止按钮,程序都没有反应,希望大家能指点我一下。我觉得是我的循环写错了,但不知道该怎么修改。


问题已经解决,答案在haijie1223那楼。 感谢haijie1223的回答。


源码如下:



#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Local $y
$hGUI = GUICreate( "New Window", 468, 324, -1, -1)
$Label1 = GUICtrlCreateLabel( "外网连接速度:"& $y, 16, 17, 115, 29)
$Button2 = GUICtrlCreateButton( "开始", 306, 139, 119, 41)
$Button3 = GUICtrlCreateButton( "停止", 306, 185, 119, 41)
GUISetState()

While 1
        $hMsg = GUIGetMsg()
       
        Switch $hMsg
                Case -3
                        Exit
                Case $Button2
                        While 1
                        $iping=Ping("www.baidu.com")
                        If $iping Then
                                $y=GUICtrlSetData($Label1,"外网连接速度:"& $iping)
                        Else
                                MsgBox(16,"警告","服务器断开连接")
                        EndIf
                        WEnd
                Case $Button3
                        $z = GUICtrlSetData($Label1,"没有启动程序")
        EndSwitch
       
WEnd
发表于 2013-1-31 09:31:17 | 显示全部楼层
回复 1# w393791998


    内层while进入死循环了
 楼主| 发表于 2013-1-31 09:35:06 | 显示全部楼层
回复 2# annybaby

我大概也猜到了,但是不知道该怎么修改。应该怎么修改呢?请赐教?
发表于 2013-1-31 09:47:22 | 显示全部楼层
 EndIf
   WEnd
改为
 EndIf
                                ExitLoop
                        WEnd
 楼主| 发表于 2013-1-31 09:57:17 | 显示全部楼层
回复 4# haijie1223


    感谢haijie1223,问题解决 虽然还不太理解这样做为什么就解决这个问题了,但是还是非常感谢,准备在研究一下。
发表于 2013-1-31 10:02:11 | 显示全部楼层
回复 5# w393791998


    去查下一下au3自带的帮助,帮助是最好的老师~
 楼主| 发表于 2013-1-31 10:08:48 | 显示全部楼层
回复 4# haijie1223
haijie1223您好,我发现一个问题  如果我添加了  ExitLoop 那么我就不能时时刷新我的那个ping的时间了,只能返回第一次的ping的结果。那还有什么方法修改吗?
发表于 2013-1-31 10:20:03 | 显示全部楼层
回复 7# w393791998


    把里层while中的内容单独拿出来做一个函数,然后注册这个函数。
发表于 2013-1-31 10:24:33 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Local $y
$hGUI = GUICreate( "New Window", 468, 324, -1, -1)
$Label1 = GUICtrlCreateLabel( "外网连接速度:"& $y, 16, 17, 115, 29)
$Button2 = GUICtrlCreateButton( "开始", 306, 139, 119, 41)
$Button3 = GUICtrlCreateButton( "停止", 306, 185, 119, 41)
GUISetState()

While 1
   $hMsg = GUIGetMsg()
   Switch $hMsg
   Case -3
          Exit
   Case $Button2
          AdlibRegister("PingIP",500) ;每500毫秒运行一次PingIP函数
   Case $Button3
          $z = GUICtrlSetData($Label1,"没有启动程序")
   EndSwitch
WEnd

AdlibUnRegister("PingIP") ;推出前注销

Func PingIP()
   $iping=Ping("www.baidu.com")
   If $iping Then
          $y=GUICtrlSetData($Label1,"外网连接速度:"& $iping)
   Else
          MsgBox(16,"警告","服务器断开连接")
   EndIf
EndFunc
发表于 2013-1-31 10:30:29 | 显示全部楼层
回复 9# cuihao777


    这样的话,退出之前是停不了函数的,把停止拿到button3后面
发表于 2013-5-25 01:30:07 | 显示全部楼层
学习了……
发表于 2013-5-26 16:29:47 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Local $y
$hGUI = GUICreate( "New Window", 468, 324, -1, -1)
$Label1 = GUICtrlCreateLabel( "外网连接速度:"& $y, 16, 17, 115, 29)
$Button2 = GUICtrlCreateButton( "开始", 306, 139, 119, 41)
$Button3 = GUICtrlCreateButton( "停止", 306, 185, 119, 41)
GUISetState()

While 1
   $hMsg = GUIGetMsg()
   Switch $hMsg
   Case -3
          Exit
   Case $Button2
          AdlibRegister("PingIP",500) ;每500毫秒运行一次PingIP函数
   Case $Button3
          $z = GUICtrlSetData($Label1,"没有启动程序")
                  AdlibUnRegister("PingIP") ;推出前注销
   EndSwitch
WEnd

Func PingIP()
   $iping=Ping("www.baidu.com")
   If $iping Then
          $y=GUICtrlSetData($Label1,"外网连接速度:"& $iping)
   Else
          MsgBox(16,"警告","服务器断开连接")
   EndIf
EndFunc
发表于 2013-5-26 16:30:12 | 显示全部楼层
这样就可以停下来了。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 03:31 , Processed in 0.104283 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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