找回密码
 加入
搜索
查看: 3575|回复: 5

[AU3基础] 帮忙看下我的程序第二个GUI为什么运行好卡?

[复制链接]
发表于 2013-6-22 09:59:37 | 显示全部楼层 |阅读模式
本帖最后由 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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2013-6-22 10:30:35 | 显示全部楼层
感觉好乱
个人意见侦测放到TIMER比较好
 楼主| 发表于 2013-6-22 10:46:05 | 显示全部楼层
回复 2# seniors


    还好吧,这个脚本就是点重新等待返回第一个UI或点退出时反应好慢!
 楼主| 发表于 2013-6-22 10:54:01 | 显示全部楼层
原来问题在 WinActivate ("Wait_TimeOut")  这句
 楼主| 发表于 2013-6-22 10:54:12 | 显示全部楼层
本帖最后由 jwwlchen 于 2013-6-22 11:33 编辑

这样就好了               
If Not WinActive("Wait_TimeOut") Then
   WinActivate ("Wait_TimeOut")               
EndIf
发表于 2013-6-22 14:55:14 | 显示全部楼层
很不错,谢谢楼主分享
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-18 13:09 , Processed in 0.083263 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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