本帖最后由 shenrenba 于 2010-9-14 19:32 编辑
我自己用的 没看你那个什么界面
#NoTrayIcon
#include <Date.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2);标题的任意子串皆可匹配
Opt("GUICloseOnESC", 0);在按下 ESC 时不退出
If _Singleton(@ScriptName, 1) = 0 Then
MsgBox(16, "警告", "该程序已经运行,禁止重复运行!", 5)
Exit
EndIf
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("时间校准器", 200, 100)
$Button1 = GUICtrlCreateButton("校准", 50, 25, 100, 50)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetState($Button1,$GUI_DISABLE)
$_Now_date = _GetSrv_Date()
$_Now_Splt = StringSplit($_Now_date, " ")
$NowData = StringSplit($_Now_Splt[1], "-")
$NowTime = StringSplit($_Now_Splt[2], ":")
_SetDate($NowData[3], $NowData[2], $NowData[1])
_SetTime($NowTime[1], $NowTime[2], $NowTime[3])
GUICtrlSetState($Button1,$GUI_ENABLE)
MsgBox(64, "提示", "时间校准完成!", 5)
EndSwitch
WEnd
Func _GetSrv_Date()
Local $_Srvlist[14] = ["time-nw.nist.gov", _
"time-a.nist.gov", _
"time-b.nist.gov", _
"time-a.timefreq.bldrdoc.gov", _
"time-b.timefreq.bldrdoc.gov", _
"time-c.timefreq.bldrdoc.gov", _
"utcnist.colorado.edu", _
"time.nist.gov", _
"nist1.datum.com", _
"nist1.dc.glassey.com", _
"nist1.ny.glassey.com", _
"nist1.sj.glassey.com", _
"nist1.aol-ca.truetime.com", _
"nist1.aol-va.truetime.com"]
UDPStartup()
Local $_Time_Srv
For $x = 0 To UBound($_Srvlist) - 1
$_Time_Srv = $_Srvlist[$x]
Local $Socket = UDPOpen(TCPNameToIP($_Time_Srv), 123)
If @error <> 0 Then ContinueLoop
$Status = UDPSend($Socket, MakePacket())
If $Status = 0 Then ContinueLoop
Local $Data = "", $i = 0
While $Data = ""
$i += 1
$Data = UDPRecv($Socket, 100)
If $i = 5 Then ContinueLoop (2)
Sleep(88)
WEnd
UDPCloseSocket($Socket)
UDPShutdown()
ExitLoop
Next
If $Data = "" Then Return 0
$Data = UnsignedHexToDec(StringMid($Data, 83, 8))
$Data = _DateTimeFormat(_DateAdd("s", $Data, "1900/01/01 08:00:00"), 0)
Return $Data
EndFunc ;==>_GetSrv_Date
Func MakePacket()
Local $P, $D = "1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
While $D
$P &= Chr(Dec(StringLeft($D, 2)))
$D = StringTrimLeft($D, 2)
WEnd
Return $P
EndFunc ;==>MakePacket
Func UnsignedHexToDec($_Data)
Return Dec(StringTrimRight($_Data, 1)) * 16 + Dec(StringRight($_Data, 1))
EndFunc ;==>UnsignedHexToDec
|