嗯,那个什么“限制输入框的类型”的帖子 那里去了?
早上看到的帖子,说是限制Input1只能是0-23,Input2只能是0-59当时看到时我挺有兴趣写了点,后来有事。
刚写了一个我的版本
让大家指正
#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <GuiEdit.au3>
Opt('MustDeclareVars', 1)
Global $hGui, $msg, $InputA, $InputB
Global $wProcNew, $wProcOld, $hInputA, $hInputB
Global $iTipIcon = $TTI_ERROR
Global $sTipTitle = "Unacceptable Character"
Global $sTipTextA = "You can only enter numbers 0 to 23 here."
Global $sTipTextB = "You can only enter numbers 0 to 59 here."
$hGui = GUICreate("Custom inputs, tooltips and cue banners for INPUT CONTROL", 450, 200)
GUICtrlCreateLabel("", -10, -10)
GUICtrlSetState(-1, $GUI_FOCUS)
$InputA = GUICtrlCreateInput("", 10, 10, 400, 30, $ES_NUMBER)
$hInputA = GUICtrlGetHandle(-1)
_GUICtrlEdit_SetCueBanner($hInputA, $sTipTextA)
$InputB = GUICtrlCreateInput("", 10, 80, 400, 30, $ES_NUMBER)
$hInputB = GUICtrlGetHandle(-1)
_GUICtrlEdit_SetCueBanner($hInputB, $sTipTextB)
$wProcNew = DllCallbackRegister("_InputWinProc", "int", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong($hInputA, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
_WinAPI_SetWindowLong($hInputB, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
GUISetState()
While True
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then _Exit()
WEnd
Func _GUICtrlEdit_SetCueBanner($hWnd, $sText)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
Local $tText = _WinAPI_MultiByteToWideChar($sText)
Return _SendMessage($hWnd, $EM_SETCUEBANNER, False, DllStructGetPtr($tText)) = 1
EndFunc
Func _Exit()
If $wProcOld Then
_WinAPI_SetWindowLong($hInputA, $GWL_WNDPROC, $wProcOld)
_WinAPI_SetWindowLong($hInputB, $GWL_WNDPROC, $wProcOld)
EndIf
If $wProcNew Then DllCallbackFree($wProcNew)
GUIDelete($hGui)
Exit
EndFunc
Func _GuiInputSetToolTip(ByRef $hWnd, ByRef $msg, ByRef $wParam, ByRef $lParam, $sTitle = "", $sText = "", $iIcon = $TTI_NONE)
If Not IsHWnd($hWnd) Then Return 0
Local $tTitle, $tText, $tTT
$tTitle = _WinAPI_MultiByteToWideChar($sTitle)
$tText = _WinAPI_MultiByteToWideChar($sText)
If $lParam And ($msg = $EM_SHOWBALLOONTIP) Then
$tTT = DllStructCreate($tagEDITBALLOONTIP, $lParam)
Else
$tTT = DllStructCreate($tagEDITBALLOONTIP)
DllStructSetData($tTT, "Size", DllStructGetSize($tTT))
EndIf
If Not IsDllStruct($tTitle) Or Not IsDllStruct($tText) Or Not IsDllStruct($tTT) Then
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $msg, $wParam, $lParam)
EndIf
DllStructSetData($tTT, "Title", DllStructGetPtr($tTitle))
DllStructSetData($tTT, "Text", DllStructGetPtr($tText))
DllStructSetData($tTT, "Icon", $iIcon)
If ($msg <> $EM_SHOWBALLOONTIP) Or (Not $lParam) Then $lParam = DllStructGetPtr($tTT)
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $EM_SHOWBALLOONTIP, $wParam, $lParam)
EndFunc
Func _InputWinProc($hWnd, $msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
Local $iStrLen, $iNum
Switch $msg
Case $EM_SHOWBALLOONTIP
Switch $hWnd
Case $hInputA
Return _GuiInputSetToolTip($hWnd, $msg, $wParam, $lParam, $sTipTitle, $sTipTextA, $iTipIcon)
Case $hInputB
Return _GuiInputSetToolTip($hWnd, $msg, $wParam, $lParam, $sTipTitle, $sTipTextB, $iTipIcon)
EndSwitch
Case $WM_CHAR
If $wParam = 7 Or $wParam = 8 Then ContinueCase
Switch $hWnd
Case $hInputA
$iStrLen = StringLen(GUICtrlRead($InputA))
If $iStrLen = 0 Then
ContinueCase
ElseIf $iStrLen = 1 Then
If GUICtrlRead($InputA) == 0 Then
$wParam = 0
Return _GuiInputSetToolTip($hWnd, $msg, $wParam, $lParam, $sTipTitle, $sTipTextA, $iTipIcon)
EndIf
$iNum = Number(GUICtrlRead($InputA) & Chr($wParam))
If $iNum > 23 Then
$wParam = 0
Return _GuiInputSetToolTip($hWnd, $msg, $wParam, $lParam, $sTipTitle, $sTipTextA, $iTipIcon)
EndIf
ElseIf $iStrLen = 2 Then
$wParam = 0
Return _GuiInputSetToolTip($hWnd, $msg, $wParam, $lParam, $sTipTitle, $sTipTextA, $iTipIcon)
EndIf
Case $hInputB
$iStrLen = StringLen(GUICtrlRead($InputB))
If $iStrLen = 0 Then
ContinueCase
ElseIf $iStrLen = 1 Then
If GUICtrlRead($InputB) == 0 Then
$wParam = 0
Return _GuiInputSetToolTip($hWnd, $msg, $wParam, $lParam, $sTipTitle, $sTipTextB, $iTipIcon)
EndIf
$iNum = Number(GUICtrlRead($InputB) & Chr($wParam))
If $iNum > 59 Then
$wParam = 0
Return _GuiInputSetToolTip($hWnd, $msg, $wParam, $lParam, $sTipTitle, $sTipTextB, $iTipIcon)
EndIf
ElseIf $iStrLen = 2 Then
$wParam = 0
Return _GuiInputSetToolTip($hWnd, $msg, $wParam, $lParam, $sTipTitle, $sTipTextB, $iTipIcon)
EndIf
EndSwitch
EndSwitch
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $msg, $wParam, $lParam)
EndFunc
回复 1# happytc
楼主厉害 回复 1# happytc
快乐兄,好像出现unacceptable character后,一定要把原先的字符删除后才能输入,不能直接改写,是不是可以改成选定字符后可以改写? 回复happytc
快乐兄,好像出现unacceptable character后,一定要把原先的字符删除后才能输入,不能直接 ...
xms77 发表于 2012-5-8 21:21 http://www.autoitx.com/images/common/back.gif
一旦出现提示,说明输入的字符已经在限制外了
这时你用鼠标选定一个字符,然后再输入一个字符来替换花的动作,还不如直接删除一个字符后再输入呢
当然,可以设定你说的那样 这个弄了内存? 做个记号,慢慢理解 本帖最后由 netegg 于 2012-6-8 11:33 编辑
大概写了个,不具有通用性(看到0-23,0-59感觉应该是时间方面的控制)
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
$formMain = GUICreate("Test", 175, 75)
GUISetState()
$dtpCtrl = GUICtrlCreateDate('', 25, 25,100, -1, BitOR($dts_timeformat, $DTS_UPDOWN))
$dtpCtrlHandle = GUICtrlGetHandle($dtpCtrl)
_GUICtrlDTP_SetFormat($dtpCtrlHandle, "H:mm")
;Local $aA =
;_GUICtrlDTP_SetRange($dtpCtrlHandle, $aA) ; 定义变化上下限
While 1
$msg = GUIGetMsg()
Switch $msg
Case $gui_event_close
Exit
EndSwitch
WEnd
学习拉,顶{:face (332):} 进来膜拜高手的!原以为提问这是咱菜鸟交流的地方,原来好多大牛都喜欢来!!! 牛X不是吹的 本帖最后由 user3000 于 2012-6-16 08:20 编辑
回复 9# benkel
膜拜下, 顺便鄙视9楼的老鬼! 你还是菜鸟啊? 那我等是小虫虫?
页:
[1]