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

[AU3基础] AdlibRegister 注册函数后,窗口无法关闭

  [复制链接]
发表于 2010-7-24 02:47:08 | 显示全部楼层 |阅读模式
代码如下:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("超越网管计费系统 _by SpriteCN", 550, 398, 195, 175, BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_GROUP), 0)
        GUISetBkColor(0x00E0FFFF)
$ButtonStar = GUICtrlCreateButton("开机", 465, 80, 75, 25)
$ButtonDown = GUICtrlCreateButton("关机", 465, 200, 75, 25)
$ButtonReboot = GUICtrlCreateButton("重启", 465, 240, 75, 25)
$ButtonAdd = GUICtrlCreateButton("续费", 465, 120, 75, 25)
$ButtonEnd = GUICtrlCreateButton("结帐", 465, 160, 75, 25)
$ButtonSenmsg = GUICtrlCreateButton("发送消息", 465, 280, 75, 25)
$Label1 = GUICtrlCreateLabel("www.zixue8.net", 425, 350)
$ButtonTotal = GUICtrlCreateButton("营业统计", 465, 320, 75, 25)
Global $listView1=GUICtrlCreateListView(" 机器编号 | 机器状态 | 预交金额 | 开始时间 | 结束时间 ",5,10,455,340)
Global $client=IniReadSection("config.ini","client")
Global $item[$client[0][0]]

AdlibRegister("_refresh",500)
For $i=1 To $client[0][0]
        $item[$i-1]=GUICtrlCreateListViewItem($client[$i][0],$listView1)
Next


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

Func _refresh()
        For $i=1 To $client[0][0]
                $var=Ping($client[$i][1],200)
                If $var Then
                        GUICtrlSetData($item[$i-1],"|在线|||")
                Else
                        GUICtrlSetData($item[$i-1],"|离线|||")
                EndIf
        Next
EndFunc
注册refresh函数后,窗口无法关闭,不注册就好好的...为什么会这样子!~!!!!
 楼主| 发表于 2010-7-24 02:52:41 | 显示全部楼层
补充下 config.ini 是这样子的

[client]
01=192.168.1.1
02=192.168.1.2
03=192.168.1.3
04=127.0.0.1
发表于 2010-7-24 07:02:32 | 显示全部楼层
机器PING坏了吧
 楼主| 发表于 2010-7-24 17:34:12 | 显示全部楼层
不可能啊..ping没有一点问题啊...127.0.0.1是显示在线的啊!~
发表于 2010-7-24 17:38:44 | 显示全部楼层
127.0.0.1是你自己。
你的目的是直到Ping通为止吗?
如果不是这个目的,是什么呢?--在函数最后加一句AdlibUnRegister("_refresh")试试
发表于 2010-7-24 17:38:54 | 显示全部楼层
不是无法关闭,而是单线程的问题,adlib内有循环未执行完,改用事件模式或取消for
 楼主| 发表于 2010-7-24 17:43:55 | 显示全部楼层
知道原因了,一次ping  的超时是250ms...500ms根本就执行不完四个ping ...

adlib 循环时间设长点,至少要把那几个ping  全部完全了就ok了


谢谢楼上各位
 楼主| 发表于 2010-7-24 17:45:45 | 显示全部楼层
回五楼...并不是ping 通为止,而是用ping 来检测机器是不是在线...

并刷新界面的机器状态.
发表于 2010-7-24 17:45:48 | 显示全部楼层
改成这样或者会好点
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("超越网管计费系统 _by SpriteCN", 550, 398, 195, 175, BitOR($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_GROUP), 0)
GUISetBkColor(0x00E0FFFF)
$ButtonStar = GUICtrlCreateButton("开机", 465, 80, 75, 25)
$ButtonDown = GUICtrlCreateButton("关机", 465, 200, 75, 25)
$ButtonReboot = GUICtrlCreateButton("重启", 465, 240, 75, 25)
$ButtonAdd = GUICtrlCreateButton("续费", 465, 120, 75, 25)
$ButtonEnd = GUICtrlCreateButton("结帐", 465, 160, 75, 25)
$ButtonSenmsg = GUICtrlCreateButton("发送消息", 465, 280, 75, 25)
$Label1 = GUICtrlCreateLabel("www.zixue8.net", 425, 350)
$ButtonTotal = GUICtrlCreateButton("营业统计", 465, 320, 75, 25)
Global $listView1 = GUICtrlCreateListView(" 机器编号 | 机器状态 | 预交金额 | 开始时间 | 结束时间 ", 5, 10, 455, 340)
Global $client = IniReadSection("config.ini", "client")
Global $item[$client[0][0]]
Global $ss = 0

AdlibRegister("_refresh", 500)
For $i = 1 To $client[0][0]
        $item[$i - 1] = GUICtrlCreateListViewItem($client[$i][0], $listView1)
Next


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

Func _refresh()
        If $ss =  $client[0][0] Then Return
        $var = Ping($client[$ss][1], 200)
        If $var Then
                GUICtrlSetData($item[$ss - 1], "|在线|||")
        Else
                GUICtrlSetData($item[$ss - 1], "|离线|||")
        EndIf
        $ss += 1
EndFunc   ;==>_refresh

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-7-24 17:50:31 | 显示全部楼层
楼上的应该不是我想要的..我想要的是定时刷新机器状态..不是只检测一次
发表于 2010-7-24 17:52:15 | 显示全部楼层
那就修改
If $ss =  $client[0][0] Then Return
改为
If $ss =  $client[0][0] Then $ss = 0
发表于 2010-7-24 18:27:14 | 显示全部楼层
消息模式资源占用太高,改用事件模式。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>

Opt("GUIOnEventMode", 1)

$Form1_1 = GUICreate("超越网管计费系统 _by SpriteCN", 550, 398, 195, 175, BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_GROUP), 0)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetBkColor(0x00E0FFFF)

$ButtonStar = GUICtrlCreateButton("开机", 465, 80, 75, 25)
$ButtonDown = GUICtrlCreateButton("关机", 465, 200, 75, 25)
$ButtonReboot = GUICtrlCreateButton("重启", 465, 240, 75, 25)
$ButtonAdd = GUICtrlCreateButton("续费", 465, 120, 75, 25)
$ButtonEnd = GUICtrlCreateButton("结帐", 465, 160, 75, 25)
$ButtonSenmsg = GUICtrlCreateButton("发送消息", 465, 280, 75, 25)
$Label1 = GUICtrlCreateLabel("www.zixue8.net", 425, 350)
$ButtonTotal = GUICtrlCreateButton("营业统计", 465, 320, 75, 25)
Global $listView1=GUICtrlCreateListView(" 机器编号 | 机器状态 | 预交金额 | 开始时间 | 结束时间 ",5,10,455,340)
Global $client=IniReadSection("config.ini","client")
Global $item[$client[0][0]]
AdlibRegister("_refresh",2000)

For $i=1 To $client[0][0]
        $item[$i-1]=GUICtrlCreateListViewItem($client[$i][0],$listView1)
Next

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
        Sleep(20)
WEnd

Func _refresh()
        For $i=1 To $client[0][0]
                $var=Ping($client[$i][1],200)
                If $var Then
                        GUICtrlSetData($item[$i-1],"|在线|||")
                Else
                        GUICtrlSetData($item[$i-1],"|离线|||")
                EndIf
                Next                
EndFunc
        
Func SpecialEvents()
        AdlibUnRegister("_refresh")
        Exit
EndFunc
        

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-7-24 23:41:14 | 显示全部楼层
我到现在还没弄明白事件模式是怎么一回事呢,其实...!!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 01:23 , Processed in 0.086293 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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