看起来使用WM_COMMAND也不麻烦,但好像点Button2后要等延时走完了才会传递函数,而使用GUIOnEventMode是即时响应的...#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=c:\documents and settings\administrator\桌面\form11.kxf
Global $StopCode
$Form1 = GUICreate("Form1", 500, 200)
$Input1 = GUICtrlCreateInput("Input1", 56, 32, 225, 21)
$Input2 = GUICtrlCreateInput("Input2", 56, 132, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 312, 24, 65, 33)
$Button2 = GUICtrlCreateButton("Button2", 400, 24, 73, 33)
$Checkbox = GUICtrlCreateCheckbox("Checkbox", 300, 132)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$StopCode = 0
GUICtrlSetData($Button1, '正在运行')
GUICtrlSetState($Button1, $GUI_DISABLE)
GUICtrlSetState($Input1, $GUI_DISABLE)
For $n = 1 To 10
If $StopCode = 1 Then ExitLoop
$ts = TimerInit()
Do
If GUIGetMsg() = -3 Then Exit
GUICtrlSetData($Input1, $n)
Until TimerDiff($ts) > 500
Next
GUICtrlSetData($Button1, '开始')
GUICtrlSetState($Button1, $GUI_ENABLE)
GUICtrlSetState($Input1, $GUI_ENABLE)
EndSwitch
WEnd
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
Local $hWndFrom, $iIDFrom, $iCode, $iIDFrom1
Switch BitAND(0xffff, $wParam)
Case $Button2
$StopCode = 1
Case $Checkbox
If GUICtrlRead($Checkbox) = $GUI_CHECKED Then
GUICtrlSetData($Input2, 1)
Else
GUICtrlSetData($Input2, 0)
EndIf
EndSwitch
EndFunc ;==>WM_COMMAND
Func _exit()
Exit
EndFunc ;==>_exit
|