Angelo Júnior BR Posted June 25, 2017 Posted June 25, 2017 Hi I need to create a mask on the control GUICtrlCreateInput to force ".", "()" and "-" between the digits. The final format would be 000.000.000-00 and the other (00)00000-0000 Can you help me Thsnks!
Deye Posted June 25, 2017 Posted June 25, 2017 (edited) Hi, How does this example work for you expandcollapse popup#include <GUIConstants.au3> #include <WinApi.au3> #include <String.au3> Global $hGUI, $idInput GUIRegisterMsg($WM_COMMAND, _WM_COMMAND) _Example() Func _Example() $hGUI = GUICreate("Example", 300, 150) $idInput = GUICtrlCreateInput("", 10, 10, 180, 25) GUICtrlSetFont(-1, 11) GUISetState(@SW_SHOW, $hGUI) While 1 Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc ;==>_Example Func InputFormated() Local $s = GUICtrlRead($idInput) If Not StringRegExp($s, '^[\d\.\-\(\)]*$') Or StringLen($s) > 14 Then Return GUICtrlSetData($idInput, StringTrimRight(GUICtrlRead($idInput), 1)) If StringLeft($s, 1) = "(" Then If StringLen($s) = 3 Then GUICtrlSetData($idInput, $s & ")") If StringLen($s) = 9 Then GUICtrlSetData($idInput, $s & "-") Else If StringLen($s) = 3 Or StringLen($s) = 7 Then GUICtrlSetData($idInput, $s & ".") If StringLen($s) = 11 Then GUICtrlSetData($idInput, $s & "-") EndIf EndFunc ;==>InputFormated Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If $hWnd = $hGUI And _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $idInput Then InputFormated() Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_COMMAND Edited June 25, 2017 by Deye Angelo Júnior BR 1
Angelo Júnior BR Posted June 25, 2017 Author Posted June 25, 2017 Woooow, very good!! Thank you very much Deye!! Is there any way I can adapt this same code to make the mask "(00)00000-0000" or do I need another one? Thanks again!
Deye Posted June 25, 2017 Posted June 25, 2017 you are welcome Changes in the above example ! Now, if your first typed character is "(" it will autocomplete to "(00)00000-0000" else it will autocomplete to "000.000.000-00" Angelo Júnior BR 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now