Code : Tout sélectionner
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("", 160, 170, -1, -1)
$Label1 = GUICtrlCreateLabel("Entrez quatres caractères :", 8, 10, 148, 17)
$Input1 = GUICtrlCreateInput("", 16, 25, 121, 21)
$Label2 = GUICtrlCreateLabel("Entrez un mot à cinq lettres :", 8, 60, 148, 17)
$Input2 = GUICtrlCreateInput("", 16, 75, 121, 21)
$Label3 = GUICtrlCreateLabel("Entrez un nombre à 2 chiffres :", 8, 110, 148, 17)
$Input3 = GUICtrlCreateInput("", 16, 125, 121, 21)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Ceci sert pour surveiller les zones d'input
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Input1
ConsoleWrite(GUICtrlRead($Input1))
EndSwitch
WEnd
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $MyInput
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; HiWord
$iCode = BitShift($iwParam, 16) ; LoWord
Switch $hWndFrom
Case GUICtrlGetHandle($Input1) ; Cas pour $Input1
Switch $iCode
Case $EN_CHANGE
; C'est ici que vous devez gérer vos contrôles sur l'input
$MyInput = GUICtrlRead($Input1) ; On récupère le texte entré
If StringLen($MyInput) >= 4 Then ; On test la longueur
GUICtrlSetState($Input2, $GUI_FOCUS) ; On met le focus le l'input suivant
EndIf
; Fin du contrôle/execution
EndSwitch
Case GUICtrlGetHandle($Input2) ; Cas pour $Input2 (que des lettres)
Switch $iCode
Case $EN_CHANGE
$MyInput = GUICtrlRead($Input2)
If Not StringInStr("abcdefghijklmnopqrstuvwxyz", StringRight($MyInput, 1)) Then ; On vérifie que la saisie est autorisée
GUICtrlSetData($Input3, StringTrimRight($MyInput, 1)) ; sinon on efface la saisie
Else ; Sinon
If StringLen($MyInput) >= 5 Then ; Test de la longueur de chaine.
GUICtrlSetState($Input3, $GUI_FOCUS) ; On met le focus le l'input suivant
EndIf
EndIf
EndSwitch
Case GUICtrlGetHandle($Input3) ; Cas pour $Input3 (nombres)
Switch $iCode
Case $EN_CHANGE
$MyInput = GUICtrlRead($Input3)
If Not StringInStr("0123456789", StringRight($MyInput, 1)) Then
GUICtrlSetData($Input3, StringTrimRight($MyInput, 1))
Else
If StringLen($MyInput) >= 2 Then
MsgBox(64 + 8192,"Saisie Terminée","Vous avez bien entré les valeurs." & @CRLF & _
"Input1 = " & GUICtrlRead($Input1) & @CRLF & _
"Input2 = " & GUICtrlRead($Input2) & @CRLF & _
"Input3 = " & GUICtrlRead($Input3) & @CRLF & @TAB)
GUIDelete($Form1)
Exit
EndIf
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND