本帖最后由 Qokelate 于 2012-3-1 23:25 编辑
怎样把下面代码那些全局变量改成局部变量并把全部功能封装在函数中?#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $UserInput, $InputLen
GUICreate("Form1", 194, 111, 192, 114)
Local $CtrlID = GUICtrlCreateEdit('', 32, 40, 131, 20)
Local $hControl = GUICtrlGetHandle($CtrlID)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState(@SW_SHOW)
Local $nMsg
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
MsgBox(0, 0, $UserInput)
Exit
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
Local $ShowStr, $BoxString, $BoxStrLen
Switch $lParam
Case $hControl
Switch $iCode
Case $EN_CHANGE
$BoxString = GUICtrlRead($CtrlID)
$BoxStrLen = StringLen($BoxString)
If $BoxStrLen < $InputLen Then
$InputLen -= 1
$UserInput = StringLeft($UserInput, $InputLen)
Else
$UserInput &= StringRight($BoxString, 1)
$InputLen += 1
EndIf
For $a = 1 To $InputLen
$ShowStr &= Random(0, 9, 1)
Next
GUICtrlSetData($CtrlID, $ShowStr)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
|