|
发表于 2010-1-2 22:43:00
|
显示全部楼层
东抄西拼,只能做到输入框不能用右键粘贴,不能能禁止键盘的快捷键,可以试下在当前GUI上注册CTRL + V 类的快捷键,但恐怕那样没意思了,并不是真正意义上的禁止.
代码有些乱七八糟,高手莫见笑!!!#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
$Form1 = GUICreate("只能输入1-50示例", 334, 98, -1, -1, $WS_THICKFRAME, -1)
$Input1 = GUICtrlCreateInput("", 112, 32, 121, 21)
$wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input1), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$CommonMenuItem = GUICtrlCreateMenuItem("这是什么?", $ContextMenu)
GUISetState(@SW_SHOW)
While 1
If _IsFocused($Form1, $Input1) And StringLen(GUICtrlRead($Input1)) > 2 Or test() Then
GUICtrlSetData($Input1, StringLeft(GUICtrlRead($Input1), StringLen(GUICtrlRead($Input1)) - 1))
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
EndSwitch
WEnd
Func _IsFocused($hWnd, $nCID)
Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))
EndFunc ;==>_IsFocused
Func test()
If StringLen(GUICtrlRead($Input1)) = 1 Then
Return Not StringRegExp(StringRight(GUICtrlRead($Input1), 1), "^[1-9]+$")
EndIf
If StringLen(GUICtrlRead($Input1)) = 2 Then
If Int(StringLeft(GUICtrlRead($Input1), 1)) > 5 Then
Return GUICtrlSetData($Input1, GUICtrlRead($Input1) & "")
EndIf
If Int(StringLeft(GUICtrlRead($Input1), 1)) = 5 Then
Return Not StringRegExp(StringRight(GUICtrlRead($Input1), 1), "^[0]+$")
Else
Return Not StringRegExp(StringRight(GUICtrlRead($Input1), 1), "^[0-9]+$")
EndIf
EndIf
EndFunc ;==>test
Func do_clever_stuff_with_clipboard($hWnd)
Local $sData
$sData = ClipGet()
If @error Then Return 0
$sData = StringUpper($sData)
GUICtrlSetData(_WinAPI_GetDlgCtrlID($hWnd), $sData)
Return 1
EndFunc ;==>do_clever_stuff_with_clipboard
Func ShowMenu($hWnd, $nContextID)
Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($nContextID), $hWnd, -1, -1, -1, -1, 2)
Switch $iSelected
Case $CommonMenuItem
;..........
EndSwitch
EndFunc ;==>ShowMenu
Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
Switch $uiMsg
Case $WM_PASTE
Return do_clever_stuff_with_clipboard($hWnd)
Case $WM_CONTEXTMENU
If $hWnd = GUICtrlGetHandle($Input1) Then
ShowMenu($Form1, $ContextMenu)
Return 0
EndIf
Case $WM_SETCURSOR
GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 5)
Return 1
EndSwitch
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>_MyWindowProc
|
评分
-
查看全部评分
|