找回密码
 加入
搜索
查看: 1775|回复: 1

[效率算法] 已解决 怎样在函数内部注册系统消息?

[复制链接]
发表于 2012-2-28 22:29:07 | 显示全部楼层 |阅读模式
本帖最后由 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
 楼主| 发表于 2012-2-28 22:30:42 | 显示全部楼层

已解决 怎样在函数内部注册系统消息?

本帖最后由 Qokelate 于 2012-3-1 09:35 编辑

这代码的作用是输入任意字符,输入框会把字符随机的变为0-9,真实的输入字符存于$UserInput变量中
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-20 23:24 , Processed in 0.081762 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表