本帖最后由 hnfeng 于 2014-11-7 14:22 编辑
当进行一个比较耗时的操作时,如何能中止这个操作呢?请教高手,谢谢
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 487, 98)
$Progress1 = GUICtrlCreateProgress(8, 72, 465, 17)
GUICtrlSetData(-1, 0)
$Button1 = GUICtrlCreateButton("开始", 48, 16, 105, 33)
$Button2 = GUICtrlCreateButton("中止", 168, 16, 105, 33)
GUICtrlSetState(-1, $gui_disable)
$Button3 = GUICtrlCreateButton("退出", 288, 16, 97, 33)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
gogo()
Case $Button3
Exit
EndSwitch
WEnd
Func gogo()
GUICtrlSetState($Button1, $gui_disable)
GUICtrlSetState($Button2, $gui_enable)
GUICtrlSetState($Button3, $gui_disable)
GUICtrlSetData($Progress1, 0)
Local $i, $j=30
For $i = 1 To $j
GUICtrlSetData($Progress1, $i * 100 / $j)
Sleep(200)
; 这里要加什么命令才能中止循环, 并得到当前的 $i
; MsgBox(0,"操作被中止","操作被中止, 最后的 $i 是:" & $i)
Next
GUICtrlSetState($Button1, $gui_enable)
GUICtrlSetState($Button2, $gui_disable)
GUICtrlSetState($Button3, $gui_enable)
EndFunc ;==>gogo
|