帮忙看下我的程序第二个GUI为什么运行好卡?
本帖最后由 jwwlchen 于 2013-6-22 10:02 编辑这是一个通过adb 侦测手机的脚本,但是第二个GUI为什么运行好卡,点击重新等待后好久才有反应,请帮忙看看哪里问题!!
代码如下:#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_UseX64=n
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
Break (0)
Dim $Wait_Time="5"
Wait_PowerON()
Func Wait_PowerON()
$Form = GuiCreate("Wait_Device", 500, 350)
$label0=GUICtrlCreateLabel("请等待。。。",30,50,400,60)
GUICtrlSetFont($label0, 25, 800, "", "Comic Sans MS")
$label1=GUICtrlCreateLabel("退出请按 ESC",300,300,400,60)
GUICtrlSetFont($label1, 20, 400, "", "Comic Sans MS")
GUICtrlSetColor($label1, 0xff0000)
$label2=GUICtrlCreateLabel("等待剩余时间 : " ,50,200,400,60)
GUICtrlSetFont($label2, 20, 800, "", "Comic Sans MS")
GuiSetState()
WinSetOnTop("Wait_Device", "", 1)
While 1
Wait_Device()
WEnd
EndFunc
Func Wait_Device()
RunWait(@ComSpec & ' /c ' & 'adb kill-server', '', 0)
RunWait(@ComSpec & ' /c ' & 'adb start-server', '', 0)
For $i = 1 To $Wait_Time
FileDelete ("dev.log")
$label2=GUICtrlCreateLabel("等待剩余时间 : " & $Wait_Time-$i ,50,200,400,60)
GUICtrlSetFont($label2, 20, 800, "", "Comic Sans MS")
RunWait(@ComSpec & ' /c ' & 'adb devices > dev.log', '', 0)
$file = FileOpen("dev.log", 0)
$line = FileReadLine($file,2)
FileClose($file)
$result = StringInStr($line, "device")
If Not $result = 0 Then
FileDelete ("dev.log")
RunWait(@ComSpec & ' /c ' & 'adb kill-server', '', 0)
Exit
Else
WinActivate ("Wait_Device")
Sleep(2000)
HotKeySet("{ESC}", "Terminate")
If $i > $Wait_Time-1 Then
FileClose("dev.log")
FileDelete ("dev.log")
WinSetOnTop("Wait_Device", "", 0)
GUIDelete()
#comments-start
MsgBox(16,"等待超时","未检测到手机!")
Do
FileClose("dev.log")
FileDelete ("dev.log")
RunWait(@ComSpec & ' /c ' & 'adb kill-server', '', 0)
ProcessClose("cmd.exe")
Until (0 == ProcessExists ( "cmd.exe" ))
#comments-end
Continue_Wait()
EndIf
EndIf
Next
EndFunc
Func Terminate()
Do
FileClose("dev.log")
FileDelete ("dev.log")
RunWait(@ComSpec & ' /c ' & 'adb kill-server', '', 0)
ProcessClose("cmd.exe")
Until (0 == ProcessExists ( "cmd.exe" ))
Exit (2)
EndFunc
Func Continue_Wait()
$Form1 = GuiCreate("Wait_TimeOut", 400, 300)
$label3=GUICtrlCreateLabel("未侦测到手机 !",30,50,400,60)
GUICtrlSetFont($label3, 25, 800, "", "Comic Sans MS")
GUICtrlSetColor($label3, 0xff0000)
$Button_1 = GUICtrlCreateButton("重新等待", 50, 200, 100)
$Button_2 = GUICtrlCreateButton("退出", 250, 200, 100)
GuiSetState()
WinSetOnTop("Wait_TimeOut", "", 1)
While 3
$msg = GUIGetMsg()
Select
Case $msg = $Button_1
GUIDelete()
Wait_PowerON()
Case $msg = $Button_2
Terminate()
EndSelect
WinActivate ("Wait_TimeOut")
WEnd
EndFunc 感觉好乱
个人意见侦测放到TIMER比较好 回复 2# seniors
还好吧,这个脚本就是点重新等待返回第一个UI或点退出时反应好慢! 原来问题在 WinActivate ("Wait_TimeOut")这句 本帖最后由 jwwlchen 于 2013-6-22 11:33 编辑
这样就好了
If Not WinActive("Wait_TimeOut") Then
WinActivate ("Wait_TimeOut")
EndIf 很不错,谢谢楼主分享
页:
[1]