AdlibRegister 注册函数后,窗口无法关闭
代码如下:#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]
AdlibRegister("_refresh",500)
For $i=1 To $client
$item[$i-1]=GUICtrlCreateListViewItem($client[$i],$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
$var=Ping($client[$i],200)
If $var Then
GUICtrlSetData($item[$i-1],"|在线|||")
Else
GUICtrlSetData($item[$i-1],"|离线|||")
EndIf
Next
EndFunc注册refresh函数后,窗口无法关闭,不注册就好好的...为什么会这样子!~!!!! 补充下 config.ini 是这样子的
01=192.168.1.1
02=192.168.1.2
03=192.168.1.3
04=127.0.0.1 机器PING坏了吧 不可能啊..ping没有一点问题啊...127.0.0.1是显示在线的啊!~ 127.0.0.1是你自己。
你的目的是直到Ping通为止吗?
如果不是这个目的,是什么呢?--在函数最后加一句AdlibUnRegister("_refresh")试试 不是无法关闭,而是单线程的问题,adlib内有循环未执行完,改用事件模式或取消for 知道原因了,一次ping的超时是250ms...500ms根本就执行不完四个ping ...
adlib 循环时间设长点,至少要把那几个ping全部完全了就ok了
谢谢楼上各位 回五楼...并不是ping 通为止,而是用ping 来检测机器是不是在线...
并刷新界面的机器状态. 改成这样或者会好点#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]
Global $ss = 0
AdlibRegister("_refresh", 500)
For $i = 1 To $client
$item[$i - 1] = GUICtrlCreateListViewItem($client[$i], $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 Then Return
$var = Ping($client[$ss], 200)
If $var Then
GUICtrlSetData($item[$ss - 1], "|在线|||")
Else
GUICtrlSetData($item[$ss - 1], "|离线|||")
EndIf
$ss += 1
EndFunc ;==>_refresh 楼上的应该不是我想要的..我想要的是定时刷新机器状态..不是只检测一次 那就修改If $ss =$client Then Return改为If $ss =$client Then $ss = 0 消息模式资源占用太高,改用事件模式。#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]
AdlibRegister("_refresh",2000)
For $i=1 To $client
$item[$i-1]=GUICtrlCreateListViewItem($client[$i],$listView1)
Next
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Sleep(20)
WEnd
Func _refresh()
For $i=1 To $client
$var=Ping($client[$i],200)
If $var Then
GUICtrlSetData($item[$i-1],"|在线|||")
Else
GUICtrlSetData($item[$i-1],"|离线|||")
EndIf
Next
EndFunc
Func SpecialEvents()
AdlibUnRegister("_refresh")
Exit
EndFunc
我到现在还没弄明白事件模式是怎么一回事呢,其实...!!!!
页:
[1]