-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestRegExp.au3
64 lines (50 loc) · 1.93 KB
/
TestRegExp.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
Global $iTimer = -1
Global $iTime_Expired = 2000
GUICreate("Input Changed GUI", 300, 140)
GUICtrlCreateLabel("You can set only numbers as 3 first characters:", 20, 40)
$Input = GUICtrlCreateInput("", 20, 70, 260, 20)
$Exit = GUICtrlCreateButton("Exit", 20, 100, 60, 20)
GUISetState()
;~ Opt("GUIOnEventMode", 1)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $Exit
ExitLoop
EndSwitch
If $iTimer <> -1 And TimerDiff($iTimer) >= $iTime_Expired Then
$iTimer = -1
GUICtrlSetBkColor($Input, 0xFFFFFF)
EndIf
WEnd
Func WM_COMMAND($hWnd, $nMsg, $wParam, $lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
Switch $nID
Case $Input
Switch $nNotifyCode
Case $EN_UPDATE
Local $sRead_Input = GUICtrlRead($Input)
Local $sFirstChars = StringLeft($sRead_Input, 3)
Local $sLastChars = ""
If StringLen($sRead_Input) > 3 Then $sLastChars = StringMid($sRead_Input, 4)
If Not StringIsDigit($sFirstChars) Then
;Uncomment this line to set a "Beep Sound" on wrong set of characters
;DllCall("User32.dll", "int", "MessageBeep", "int", -1)
$iTimer = TimerInit()
GUICtrlSetBkColor($Input, 0xFFCACA)
GUICtrlSetData($Input, StringRegExpReplace($sFirstChars, "[^\d]+", "") & $sLastChars)
Else
$iTimer = -1
GUICtrlSetBkColor($Input, 0xFFFFFF)
EndIf
Case $EN_SETFOCUS
Case $EN_KILLFOCUS
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc