#include <WinAPI.au3>
If not IsDeclared("WM_CHAR") Then CONST $WM_CHAR = 0x102
If not IsDeclared("WM_PASTE") Then CONST $WM_PASTE = 0x302
If not IsDeclared("WM_SETTEXT") Then CONST $WM_SETTEXT = 0xc
$hGUI = GUICreate("Test", 200, 100)
$iIptTest = GUICtrlCreateInput("", 20, 20, 160, 20)
$hIpt = GUICtrlGetHandle(-1)
$hIptProc = DllCallbackRegister("_IptProc", "int", "hWnd;uint;wparam;lparam")
$pIptProc = DllCallbackGetPtr($hIptProc)
$hOldProc = _WinAPI_SetWindowLong($hIpt, -4, $pIptProc)
GUISetState()
Do
Until guiGetMsg() = -3
Func _IptProc($hWnd, $iMsg, $wParam, $lParam)
ConsoleWrite("0x" & Hex($iMsg) & @CRLF)
If $iMsg = $WM_CHAR Then
If $wparam <> 8 And $wparam < 128 Then
_WinAPI_MessageBeep(2)
Return False
EndIf
ElseIf $iMsg = $WM_PASTE Then
If StringRegExp(ClipGet(), "[\x20-\x7f]") Then Return False
ElseIf $iMsg = $WM_SETTEXT Then
_WinAPI_MessageBeep(2)
Return False
EndIf
Return _WinAPI_CallWindowProc($hOldProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc ;==>_IptProc()
以上,限制只能输入/粘贴汉字。。。若限制只能输入英文和数字,把$wparam < 128 改为StringRegExp(Chr($wparam), "[0-9a-zA-Z]") = 0就好了。
[ 本帖最后由 pusofalse 于 2009-4-9 02:36 编辑 ] |