Jump to content

Recommended Posts


How does this example work for you

#include <GUIConstants.au3>
#include <WinApi.au3>
#include <String.au3>

Global $hGUI, $idInput



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
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 & "-")
        If StringLen($s) = 3 Or StringLen($s) = 7 Then GUICtrlSetData($idInput, $s & ".")
        If StringLen($s) = 11 Then GUICtrlSetData($idInput, $s & "-")
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 by Deye
Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...