GUICtrlCreateInput可不可以让其不能输入中文?
如果不能,那能不能在$Input1 = GUICtrlCreateInput
$1 = GUICtrlRead(Input1)
If $1 =
然后写什么让他见到中文就msgbox
可以正则 ;$Input1 = GUICtrlCreateInput
;$1 = GUICtrlRead(Input1)
if StringRegExp($1,'[^\x00-\xff]') Then
MsgBox(0, 0, '含有汉字或双字节字符')
EndIf 我觉得不如限制只能输入英文及数字比较好 以前有过只能输入数字不能输入其它的UDF,根据二楼提供的正则.修改一下应该可以满足你的需要.
修改过的 额,忘了说了,特殊符号必须允许 只要不是双字节字符就好办,au3貌似不好区分双字节字符和汉字 哦,是我错了 再次请教 bing614 :
能不能搞个大于16字符,就会跟输入中文有那个tooltip,我怎么都搞不好
Global $sToolTip_Text[?] = ["对不起,不能大于16个字符!", "错误:"] 是不是大于16个字符就显示["对不起,不能大于16个字符!", "错误:"] 本帖最后由 bing614 于 2009-9-7 21:19 编辑
#include-once
#include <GuiConstants.au3>
If Not IsDeclared("WM_COMMAND") Then Global Const $WM_COMMAND = 0x0111
If Not IsDeclared("WM_MOVE") Then Global Const $WM_MOVE = 0x0003
If Not IsDeclared("WM_LBUTTONDOWN") Then Global Const $WM_LBUTTONDOWN = 0x0201
If Not IsDeclared("WM_RBUTTONDOWN") Then Global Const $WM_RBUTTONDOWN = 0x0204
Global $sToolTip_Text = ["对不起,不支持中文字符!", "错误:","仅支持长度小于16的字符串!"]
Global $sInputs_Array
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUIRegisterMsg($WM_MOVE, "WM_CLEAR_TOOLTIP")
GUIRegisterMsg($WM_LBUTTONDOWN, "WM_CLEAR_TOOLTIP")
GUIRegisterMsg($WM_RBUTTONDOWN, "WM_CLEAR_TOOLTIP")
; $CtrlId must be an ID value, -1 can not be used!
Func _GuiInputSetOnlyNumbers($CtrlId)
Local $iUbound = UBound($sInputs_Array)
ReDim $sInputs_Array[$iUbound+1]
$sInputs_Array[$iUbound] = $CtrlId
EndFunc
Func _Input_Changed($hWnd, $CtrlId)
ToolTip("")
Local $Read_Input = GUICtrlRead($CtrlId)
if StringRegExp($Read_Input,'[^\x00-\xff]') Then
GUICtrlSetData($CtrlId, StringRegExpReplace($Read_Input, '[^\x00-\xff]', ''))
Local $Gui_Get_Pos = WinGetPos($hWnd)
Local $Ctrl_Get_Pos = ControlGetPos($hWnd, "", $CtrlId)
Local Const $SM_CYCAPTION = 4 ;Titelbar heigth
Local Const $SM_CXFIXEDFRAME = 7 ;Window border size
Local $X_Pos = $Gui_Get_Pos + $Ctrl_Get_Pos + $Ctrl_Get_Pos + GetSystemMetrics($SM_CXFIXEDFRAME)
Local $Y_Pos = $Gui_Get_Pos + $Ctrl_Get_Pos + $Ctrl_Get_Pos + GetSystemMetrics($SM_CYCAPTION)
ToolTip($sToolTip_Text, $X_Pos, $Y_Pos, $sToolTip_Text, 3, 1+4)
DllCall("user32.dll", "int", "MessageBeep", "int", 0x0)
Else
If StringLen($Read_Input) >16 Then ;如果字符长度大于16时
GUICtrlSetData($CtrlId, StringLeft($Read_Input,16)) ;截取前16个字符
Local $Gui_Get_Pos = WinGetPos($hWnd)
Local $Ctrl_Get_Pos = ControlGetPos($hWnd, "", $CtrlId)
Local Const $SM_CYCAPTION = 4 ;Titelbar heigth
Local Const $SM_CXFIXEDFRAME = 7 ;Window border size
Local $X_Pos = $Gui_Get_Pos + $Ctrl_Get_Pos + $Ctrl_Get_Pos + GetSystemMetrics($SM_CXFIXEDFRAME)
Local $Y_Pos = $Gui_Get_Pos + $Ctrl_Get_Pos + $Ctrl_Get_Pos + GetSystemMetrics($SM_CYCAPTION)
ToolTip($sToolTip_Text, $X_Pos, $Y_Pos, $sToolTip_Text, 3, 1+4)
DllCall("user32.dll", "int", "MessageBeep", "int", 0x0)
EndIf
EndIf
EndFunc
Func WM_CLEAR_TOOLTIP($hWnd, $iMsg, $wParam, $lParam)
ToolTip("")
Return $GUI_RUNDEFMSG
EndFunc
Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
If $hWnd = 0 Or Not WinExists($hWnd) Then Return $GUI_RUNDEFMSG
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local Const $EN_CHANGE = 0x300
Local Const $EN_UPDATE = 0x400
Local Const $EN_SETFOCUS = 0x100
Local Const $EN_KILLFOCUS = 0x200
For $i = 1 To UBound($sInputs_Array)-1
If $nID = $sInputs_Array[$i] Then
Switch $nNotifyCode
Case $EN_UPDATE ;$EN_CHANGE
_Input_Changed($hWnd, $sInputs_Array[$i])
Case $EN_SETFOCUS, $EN_KILLFOCUS
ToolTip("")
EndSwitch
ExitLoop
EndIf
Next
Return $GUI_RUNDEFMSG
EndFunc
Func GetSystemMetrics($Flag)
Local $iRet = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $Flag)
Return $iRet
EndFunc
这个你只要在 $Input1 = GUICtrlCreateInput(...)
下面加一句 GUICtrlSetLimit(-1, 16) 即可~ 用不着提示,直接就不让你输入了 总这个错误>运行 AU3Check (1.54.15.0)开始目录:D:\autoit3
R:\GUIInputSetOnlyNumbers.au3(42,50) : ERROR: $SM_CYCAPTION previously declared as a 'Const'
Local Const $SM_CYCAPTION = 4 ;Titelbar heigth
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
R:\GUIInputSetOnlyNumbers.au3(43,58) : ERROR: $SM_CXFIXEDFRAME previously declared as a 'Const'
Local Const $SM_CXFIXEDFRAME = 7 ;Window border size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
R:\GUIInputSetOnlyNumbers.au3 - 2 error(s), 0 warning(s)
!>21:25:29 AU3Check 结束::2
+>21:25:29 ACNWrapper 完成!
>退出代码: 0 时间: 0.560所以改了下
#include-once
#include <GuiConstants.au3>
If Not IsDeclared("WM_COMMAND") Then Global Const $WM_COMMAND = 0x0111
If Not IsDeclared("WM_MOVE") Then Global Const $WM_MOVE = 0x0003
If Not IsDeclared("WM_LBUTTONDOWN") Then Global Const $WM_LBUTTONDOWN = 0x0201
If Not IsDeclared("WM_RBUTTONDOWN") Then Global Const $WM_RBUTTONDOWN = 0x0204
Global $sToolTip_Text = ["对不起,不支持中文字符!", "错误:","仅支持长度小于16的字符串!"]
Global $sInputs_Array
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUIRegisterMsg($WM_MOVE, "WM_CLEAR_TOOLTIP")
GUIRegisterMsg($WM_LBUTTONDOWN, "WM_CLEAR_TOOLTIP")
GUIRegisterMsg($WM_RBUTTONDOWN, "WM_CLEAR_TOOLTIP")
; $CtrlId must be an ID value, -1 can not be used!
Func _GuiInputSetOnlyNumbers($CtrlId)
Local $iUbound = UBound($sInputs_Array)
ReDim $sInputs_Array[$iUbound+1]
$sInputs_Array[$iUbound] = $CtrlId
EndFunc
Func _Input_Changed($hWnd, $CtrlId)
ToolTip("")
Local $Read_Input = GUICtrlRead($CtrlId)
if StringRegExp($Read_Input,'[^\x00-\xff]') Then
GUICtrlSetData($CtrlId, StringRegExpReplace($Read_Input, '[^\x00-\xff]', ''))
Local $Gui_Get_Pos = WinGetPos($hWnd)
Local $Ctrl_Get_Pos = ControlGetPos($hWnd, "", $CtrlId)
Local Const $SM_CYCAPTION = 4 ;Titelbar heigth
Local Const $SM_CXFIXEDFRAME = 7 ;Window border size
Local $X_Pos = $Gui_Get_Pos + $Ctrl_Get_Pos + $Ctrl_Get_Pos + GetSystemMetrics($SM_CXFIXEDFRAME)
Local $Y_Pos = $Gui_Get_Pos + $Ctrl_Get_Pos + $Ctrl_Get_Pos + GetSystemMetrics($SM_CYCAPTION)
ToolTip($sToolTip_Text, $X_Pos, $Y_Pos, $sToolTip_Text, 3, 1+4)
DllCall("user32.dll", "int", "MessageBeep", "int", 0x0)
Else
If StringLen($Read_Input) >16 Then ;如果字符长度大于16时
GUICtrlSetData($CtrlId, StringLeft($Read_Input,16)) ;截取前16个字符
Local $Gui_Get_Pos = WinGetPos($hWnd)
Local $Ctrl_Get_Pos = ControlGetPos($hWnd, "", $CtrlId)
Local Const $SM_CYCAPTION = 4 ;Titelbar heigth
Local Const $SM_CXFIXEDFRAME = 7 ;Window border size
Local $X_Pos = $Gui_Get_Pos + $Ctrl_Get_Pos + $Ctrl_Get_Pos + GetSystemMetrics($SM_CXFIXEDFRAME)
Local $Y_Pos = $Gui_Get_Pos + $Ctrl_Get_Pos + $Ctrl_Get_Pos + GetSystemMetrics($SM_CYCAPTION)
ToolTip($sToolTip_Text, $X_Pos, $Y_Pos, $sToolTip_Text, 3, 1+4)
DllCall("user32.dll", "int", "MessageBeep", "int", 0x0)
EndIf
EndIf
EndFunc
Func WM_CLEAR_TOOLTIP($hWnd, $iMsg, $wParam, $lParam)
ToolTip("")
Return $GUI_RUNDEFMSG
EndFunc
Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
If $hWnd = 0 Or Not WinExists($hWnd) Then Return $GUI_RUNDEFMSG
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local Const $EN_CHANGE = 0x300
Local Const $EN_UPDATE = 0x400
Local Const $EN_SETFOCUS = 0x100
Local Const $EN_KILLFOCUS = 0x200
For $i = 1 To UBound($sInputs_Array)-1
If $nID = $sInputs_Array[$i] Then
Switch $nNotifyCode
Case $EN_UPDATE ;$EN_CHANGE
_Input_Changed($hWnd, $sInputs_Array[$i])
Case $EN_SETFOCUS, $EN_KILLFOCUS
ToolTip("")
EndSwitch
ExitLoop
EndIf
Next
Return $GUI_RUNDEFMSG
EndFunc
Func GetSystemMetrics($Flag)
Local $iRet = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $Flag)
Return $iRet
EndFunc
WM_CHAR
_WinAPI_SetWindowLong 不错的解决方法,我已经使用了4楼的方法,现在想再借鉴一下,能否禁止输入其他字符。 p侠,想不想让我掐死楼上的
页:
[1]
2