好的,我正在创建一个AutoIt GUI可执行文件来自动化网站中的某些功能。但是,我无法找到一种方法来打破执行我使用" STOP"创建的函数的While循环。按钮我已创建。因此,它无限期运行,我不能退出该程序。从理论上讲,它应该有效,但我觉得我错过了一些东西。有人帮忙吗?
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
Global $msg, $instructions, $AutoLevel, $NumDogsBox, $NumDogs, $IE, $i, $o
$IE = _IECreateEmbedded()
GUICreate("Automatic Dog Feeder for Criminal Case", 900, 690)
$instructions = GUICtrlCreateButton(' Instructions ', 725, 5)
GUICtrlCreateLabel("# of Dogs: ",740,40)
$NumDogsBox = GUICtrlCreateInput("", 815, 37, 25)
$AutoLevel = GUICtrlCreateButton(' Begin Auto Feed Dog ', 700, 65)
GUICtrlCreateObj($IE, 1, 100, 915, 610)
GUISetState(@SW_SHOW)
_IENavigate($IE, "http://apps.facebook.com/criminalcase")
$IE.Document.Body.Scroll = "no"
_IEAction($IE, "stop")
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $instructions
MsgBox(0,"Instructions","1.) Log in to Facebook (if not already) in the window below" & @CRLF & "2.) Clear any notifications and get to the map screen" & @CRLF & "3.) Click on the dog bowl icon on the right of the map" & @CRLF & "4.) Enter the number of dogs you have to level up" & @CRLF & "5.) Click the Begin Auto Feed Dog button at the bottom of the window")
Case $msg = $AutoLevel
$NumDogs = GUICtrlRead($NumDogsBox)
AutoDogLevel()
EndSelect
WEnd
Func AutoDogLevel()
While 1
$stop = GUICtrlCreateButton('STOP',830,65)
$i=0
While $i < $NumDogs
If $msg = $stop Then
ExitLoop
Endif
MsgBox(0,"","1xp" & $i+1)
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]","","","left",1,156,651)
Sleep(2000)
If $msg = $stop Then
ExitLoop
Endif
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]","","","left",1,723,524)
MsgBox(0,"","Next Dog")
Sleep(2000)
$i = $i+1
WEnd
If $msg = $stop Then
ExitLoop
Endif
While $i > 0
If $msg = $stop Then
ExitLoop
Endif
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]","","","left",1,62,525)
MsgBox(0,"","Previous Dog")
If $msg = $stop Then
ExitLoop
Endif
Sleep(1000)
$i=$i-1
WEnd
If $msg = $stop Then
ExitLoop
Endif
Sleep(3000)
WEnd
EndFunc
所以,现在我被卡住了。任何帮助将不胜感激。
答案 0 :(得分:1)
为GUI设置多个消息循环不是一个好主意。我没有这样做,而是建议为当前状态保留一个变量,并且只实现一个循环。你也在消息循环中有一些非常大的睡眠。
我还没有对代码进行测试,但是这里是重写的消息循环,使用状态变量和定时器而不是多个循环和休眠。这是一个更好的设计,可以确保您的GUI始终响应所有按钮,我认为一旦您习惯了结构,我也会发现它更容易使用。
Local $iState = 0, $i, $iTimer
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $instructions
MsgBox(0, "Instructions", "1.) Log in to Facebook (if not already) in the window below" & @CRLF & "2.) Clear any notifications and get to the map screen" & @CRLF & "3.) Click on the dog bowl icon on the right of the map" & @CRLF & "4.) Enter the number of dogs you have to level up" & @CRLF & "5.) Click the Begin Auto Feed Dog button at the bottom of the window")
Case $msg = $AutoLevel
$NumDogs = GUICtrlRead($NumDogsBox)
$stop = GUICtrlCreateButton('STOP', 830, 65)
$iState = 1
$i = 0
Case Else
If $iState = 1 Then
If $i >= $NumDogs Then
$iState = 3
ContinueLoop
EndIf
MsgBox(0, "", "1xp" & $i + 1)
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]", "", "", "left", 1, 156, 651)
$iState = 2
$iTimer = TimerInit()
ElseIf $iState = 2 Then
If TimerDiff($iTimer) < 2000 Then ContinueLoop
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]", "", "", "left", 1, 723, 524)
MsgBox(0, "", "Next Dog")
$iTimer = TimerInit()
$i = $i + 1
ElseIf $iState = 3 Then
If TimerDiff($iTimer) < 1000 Then ContinueLoop
If $i <= 0 Then
$iState = 1
ContinueLoop
EndIf
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]", "", "", "left", 1, 62, 525)
MsgBox(0, "", "Previous Dog")
$iTimer = TimerInit()
$i = $i - 1
EndIf
EndSelect
WEnd