【已解决】创建一个GUICtrlCreateInput后,输入4个字符后执行某个函数?
本帖最后由 netsmu 于 2011-6-3 08:53 编辑创建一个GUICtrlCreateInput,能不能输入4个字符后自动执行某个函数?
要求不能在循环里面,不影响界面其他功能的执行。
还有个问题 InputBox 能不能输入4个字符后,自动点确定,或者执行回车事件呢?
谢谢各位的帮助。 #include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 629, 106, 192, 132)
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 433, 24)
$Button1 = GUICtrlCreateButton("Button1", 496, 32, 105, 33)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
mem(GUICtrlRead($Input1))
GUICtrlSetData($Input1,'')
EndSwitch
WEnd
Func mem($string)
msgbox(0,0,$string)
EndFunc
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local Const $EN_CHANGE = 0x300
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
if $nID =$Input1 Then
If $nNotifyCode = $EN_CHANGE Then
If StringLen(GUICtrlRead($Input1)) >=4Then
mem(GUICtrlRead($Input1))
GUICtrlSetData($Input1,'')
;GUICtrlSetData($Input1,StringLeft(GUICtrlRead($Input1),4))
EndIf
EndIf
EndIf
EndFunc ;==>MY_WM_COMMAND 问题解决,楼上代码挺好的,谢谢3mile 还有个问题 InputBox 能不能输入4个字符后,自动点确定,或者执行回车事件呢? 还有个问题 InputBox 能不能输入4个字符后,自动点确定,或者执行回车事件呢?
netsmu 发表于 2011-6-3 08:53 http://www.autoitx.com/images/common/back.gif
2楼的代码不正是自动运行$BUTTON的吗? 这个有用,解决了一个大问题Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local Const $EN_CHANGE = 0x300
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
if $nID =$day1 Then
If $nNotifyCode = $EN_CHANGE Then
;MsgBox( 4096, "", "计算时间: " & $sNewDate )
$sNewDate5 = _DateAdd( 'h',9, GUICtrlRead($date))
$sNewDate = _DateAdd( 'd',-GUICtrlRead($day1)+1, GUICtrlRead($date))
GUICtrlCreateLabel("Microsoft project结果:日期为"& $sNewDate , 20, 215)
GUICtrlCreateLabel("基准日期:"& $sNewDate5 , 20, 170)
GUICtrlSetColor(-1, 0xff0000)
EndIf
EndIf
if $nID =$day2 Then
If $nNotifyCode = $EN_CHANGE Then
If GUICtrlRead($day2)<> 0 Then
$sNewDate1 = _DateAdd( 'h',9, GUICtrlRead($date))
$sNewDate1 = _DateAdd( 'd',GUICtrlRead($day2)-1, $sNewDate1)
Else
$sNewDate1 = _DateAdd( 'd',GUICtrlRead($day2), GUICtrlRead($date))
EndIf
GUICtrlCreateLabel("Microsoft project结果:日期为"& $sNewDate1 , 20, 315)
GUICtrlCreateLabel("基准日期:"& GUICtrlRead($date) , 20, 270)
GUICtrlSetColor(-1, 0xff0000)
EndIf
EndIf
EndFunc ;==>MY_WM_COMMAND
页:
[1]