回复 11# changwang
#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
这里有一个较为理想的方法 |