#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 629, 106, 192, 132)
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 433, 24)
$Button1 = GUICtrlCreateButton("Button1", 496, 32, 105, 33)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($Input1, '')
EndSwitch
WEnd
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local Const $EN_CHANGE = 0x300
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
If $nID = $Input1 Then
If $nNotifyCode = $EN_CHANGE Then
$read=GUICtrlRead($Input1)
If String(StringLeft($read,2))=="00" Then
GUICtrlSetData($Input1,StringRegExpReplace($read,'^0+',''))
ElseIf String(StringLeft($read,1))=="." Then
GUICtrlSetData($Input1,StringRegExpReplace($read,'(^\.)+','0.'))
Else
$write=StringRegExpReplace($read,'[^\.0-9]+','')
$temp=StringSplit($write,".",1+2)
if UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
GUICtrlSetData($Input1,$write)
EndIf
EndIf
EndIf
EndFunc
|