#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <Date.au3>
GUICreate("Form1", 400, 300)
$Date1 = GUICtrlCreateDate("", 100, 10, 91, 28)
$Date2 = GUICtrlCreateDate("", 100, 110, 91, 28)
$Date3 = GUICtrlCreateDate("", 100, 210, 91, 28)
$Button1 = GUICtrlCreateButton("E", 250, 100, 100, 30)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1
MsgBox(0, '', '相应键')
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndDate1, $tInfo
If Not IsHWnd($Date1) Then $hWndDate1 = GUICtrlGetHandle($Date1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iCode
Case $NM_KILLFOCUS
Switch $iIDFrom
Case $Date1 To $Date3 ; 控件失去输入焦点
_Time($iIDFrom)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _Time($ID);定义时间比较函数
$Time_Array = StringRegExp(GUICtrlRead($ID), "\d+", 3)
$Time = $Time_Array[0] & "/" & $Time_Array[1] & "/" & $Time_Array[2]
$iDateCalc = _DateDiff("D", $Time, _NowCalc())
If $iDateCalc > 0 Then Return 1 ;如果控件时间小于现在时间返回1
If $iDateCalc = 0 Then Return 0; 如果控件时间等于现在时间返回0
If $iDateCalc < 0 Then
MsgBox(262144,"提示","选择日期不能超过当前日期,请重新输入!")
GUICtrlSetData($Date1,@YEAR&"年"&@MON&"月"&@MDAY&"日")
GUICtrlSetState ($Date1,$GUI_FOCUS)
Return -1 ;如果控件时间大于现在时间返回-1
EndIf
EndFunc ;==>_Time
|