Crée un contrôle Date Time Picker (DTP), qui permet de saisir une date et une heure
#include <GuiDateTimePicker.au3>
_GUICtrlDTP_Create ( $hWnd, $iX, $iY [, $iWidth = 120 [, $iHeight = 21 [, $iStyle = 0x00000000 [, $iExStyle = 0x00000000]]]] )
$hWnd | Handle de la fenêtre parent ou propriétaire |
$iX | Position horizontale du contrôle |
$iY | Position verticale du contrôle |
$iWidth | [optionnel] Largeur du contrôle |
$iHeight | [optionnel] Hauteur de contrôle |
$iStyle | [optionnel] Styles du contrôle: $DTS_APPCANPARSE - Permet au propriétaire d'analyser l'entrée de l'utilisateur et de prendre des mesures $DTS_LONGDATEFORMAT - Affiche la date dans le format long $DTS_RIGHTALIGN - Le calendrier sera aligné à droite $DTS_SHOWNONE - Affiche une case à cocher qui peut être cochée une fois que la date est entrée $DTS_SHORTDATEFORMAT - Affiche la date dans le format court $DTS_SHORTDATECENTURYFORMAT - L'année est un champ à quatre chiffres $DTS_TIMEFORMAT - Affiche l'heure $DTS_UPDOWN - Place un contrôle haut-bas à la droite du contrôle Forcé: $WS_CHILD, $WS_VISIBLE |
$iExStyle | [optionnel] Styles étendus du contrôle. Ils correspondent aux constantes standards $WS_EX_*. Consultez Table des styles étendus. |
Succès: | Retourne le handle du contrôle DTC. |
Échec: | Retourne 0. |
Cette fonction est destinée aux utilisateurs avertis et à ceux qui veulent comprendre comment fonctionne le contrôle.
#include <GUIConstantsEx.au3> #include <GuiDateTimePicker.au3> #include <WindowsConstants.au3> Global $g_hDTP Example() Func Example() Local $hGUI ; Crée une GUI $hGUI = GUICreate("(UDF Created) DateTimePick Create", 400, 300) $g_hDTP = _GUICtrlDTP_Create($hGUI, 2, 6, 190) GUISetState(@SW_SHOW) ; Définit le format d'affichage _GUICtrlDTP_SetFormat($g_hDTP, "ddd MMM dd, yyyy hh:mm ttt") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Boucle jusqu'à ce que l'utilisateur quitte. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tBuffer, $tBuffer2 $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $g_hDTP Switch $iCode Case $DTN_CLOSEUP ; Envoyé par un contrôle 'date and time picker' (DTP) quand l'utilisateur ferme le calendrier mensuel déroulant _DebugPrint("$DTN_CLOSEUP" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; La valeur retournée pour cette notification n'est pas utilisée Case $DTN_DATETIMECHANGE ; Envoyé par un contrôle 'date and time picker' (DTP) quand un changement se produit $tInfo = DllStructCreate($tagNMDATETIMECHANGE, $lParam) _DebugPrint("$DTN_DATETIMECHANGE" & @CRLF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->Flag:" & @TAB & DllStructGetData($tInfo, "Flag") & @CRLF & _ "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _ "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _ "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _ "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _ "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _ "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _ "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _ "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond")) Return 0 Case $DTN_DROPDOWN ; Envoyé par un contrôle 'date and time picker' (DTP) quand l'utilisateur active le calendrier mensuel déroulant _DebugPrint("$DTN_DROPDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; La value retournée par cette notification n'est pas utilisée Case $DTN_FORMAT ; Envoyé par un contrôle 'date and time picker' (DTP) pour demander le texte qui doit être affiché dans un champ de retour $tInfo = DllStructCreate($tagNMDATETIMEFORMAT, $lParam) $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format")) $tBuffer2 = DllStructCreate("char Display[64]", DllStructGetData($tInfo, "pDisplay")) _DebugPrint("$DTN_FORMAT" & @CRLF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _ "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _ "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _ "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _ "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _ "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _ "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _ "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _ "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond") & @CRLF & _ "-->Display:" & @TAB & DllStructGetData($tBuffer2, "Display")) Return 0 Case $DTN_FORMATQUERY ; Envoyé par un contrôle 'date and time picker' (DTP) pour récupérer la taille maximale allouée à la chaîne qui doit être affichée dans un champ de retour $tInfo = DllStructCreate($tagNMDATETIMEFORMATQUERY, $lParam) $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format")) _DebugPrint("$DTN_FORMATQUERY" & @CRLF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _ "-->SizeX:" & @TAB & DllStructGetData($tInfo, "SizeX") & @CRLF & _ "-->SizeY:" & @TAB & DllStructGetData($tBuffer2, "SizeY")) DllStructSetData($tInfo, "SizeX", 64) DllStructSetData($tInfo, "SizeY", 10) Return 0 Case $DTN_USERSTRING ; Envoyé par un contrôle 'date and time picker' (DTP) quand l'utilisateur a fini d'éditer une chaîne dans le contrôle $tInfo = DllStructCreate($tagNMDATETIMESTRING, $lParam) $tBuffer = DllStructCreate("char UserString[128]", DllStructGetData($tInfo, "UserString")) _DebugPrint("$DTN_USERSTRING" & @CRLF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->UserString:" & @TAB & DllStructGetData($tBuffer, "UserString") & @CRLF & _ "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _ "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _ "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _ "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _ "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _ "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _ "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _ "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond") & @CRLF & _ "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags")) Return 0 Case $DTN_WMKEYDOWN ; Envoyé par un contrôle 'date and time picker' (DTP) quand l'utilisateur tape dans un champ de retour $tInfo = DllStructCreate($tagNMDATETIMEFORMATQUERY, $lParam) $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format")) _DebugPrint("$DTN_WMKEYDOWN" & @CRLF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->VirtKey:" & @TAB & DllStructGetData($tInfo, "VirtKey") & @CRLF & _ "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _ "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _ "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _ "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _ "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _ "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _ "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _ "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _ "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond")) Return 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint