Autoit之-循环外退出循环(转)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 32, 24, 545, 201)
$Button1 = GUICtrlCreateButton("start_click", 104, 256, 121, 41)
$Button2 = GUICtrlCreateButton("stop_click", 328, 256, 121, 41)
$hButton = GUICtrlGetHandle($Button2)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
 
;===============================================
Global $num, $Paused, $stop = False
HotKeySet("{PAUSE}", "AutoIt_Pause")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
;===============================================
 
While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        start_click()
        EndSwitch
WEnd
 
Func start_click()
        $stop = False
        While 1
                Sleep(100)
                GUICtrlSetData($Edit1, $num & @CRLF, 1)
                $num += 1
                If $stop Then ExitLoop;也可以是Return
        WEnd
        GUICtrlSetData($Edit1, '$stop = ' & $stop & @CRLF, 1)
        GUICtrlSetData($Edit1, '该函数已经退出', 1)
EndFunc   ;==>start_click
 
Func AutoIt_Pause()
        $stop = True
EndFunc   ;==>AutoIt_Pause
 
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
        $iCode = BitShift($iwParam, 16)
        Switch $ilParam
                Case $hButton
                        If $iCode = $BN_CLICKED Then $stop = True
        EndSwitch
EndFunc   ;==>WM_COMMAND

 出自:http://www.autoitx.com/viewthread.php?tid=19546&highlight=%D4%F5%C3%B4%D4%DA%D1%AD%BB%B7%CD%E2%B2%BF%CD%CB%B3%F6%D1%AD%BB%B7

posted @ 2012-09-05 17:51  怡然^o^恬谧  阅读(956)  评论(0)    收藏  举报