好的,所以我正在创建一个AutoIt GUI可执行文件来自动执行网站中的一些功能。但是,我找不到一种方法来中断While循环,该循环执行我使用我创建的"STOP"按钮创建的函数。因此,它无限期地运行,我不能退出程序。理论上,它应该能起作用,但我觉得我遗漏了一些东西。有什么需要帮忙的吗?
#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
所以,现在我被卡住了。
在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