Last active
January 3, 2016 15:09
-
-
Save tmplinshi/8480830 to your computer and use it in GitHub Desktop.
注: 还需要其他文件才能运行。下载地址: http://pan.baidu.com/s/1Wsyy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ============================================================== | |
; 北京时间校准器 | |
; v1.04 / 2014-9-8 / tmplinshi | |
; -------------------------------------------------------------- | |
; AutoHotkey 版本: 1.1.13.01 | |
; 感谢 : "just me" 的 Class_ImageButton | |
; ============================================================== | |
;----------------------------------------- | |
/* | |
[config] | |
ahk_version=Unicode | |
icon=clock.ico | |
bin= | |
*/ | |
;@Ahk2Exe-SetVersion 1.0.4.0 | |
;----------------------------------------- | |
#NoEnv | |
#SingleInstance force | |
#Include <Class_ImageButton> | |
#Include <Class_CustomFont> | |
SetBatchLines, -1 | |
OnExit, ExitSub | |
; 以管理员身份运行 | |
if not A_IsAdmin | |
{ | |
Run, *RunAs "%A_ScriptFullPath%" | |
ExitApp | |
} | |
; 去掉托盘菜单 | |
Menu, Tray, NoStandard | |
; ================================= | |
; 命令行方式启动 | |
; ================================= | |
if 1 = /Auto | |
{ | |
TrayTip, 北京时间校准器, 正在获取标准时间... | |
Gosub, GetBeijingTime | |
TrayTip, 北京时间校准器, 正在校准时间... | |
Gosub, btn_JiaoDui | |
TrayTip, 北京时间校准器, 校准完毕!2 秒后退出... | |
Sleep, 2000 | |
ExitApp | |
} | |
; ================================= | |
; 界面 | |
; ================================= | |
Gui, -Caption +hwndhGui +E0x1 +E0x200 ; WS_EX_DLGMODALFRAME(带双层边框)=0x1, WS_EX_CLIENTEDGE(带阴影的边缘)=0x200 | |
Gui, Margin, 0, 0 | |
Gui, Color, FFFFFF | |
Gui, Font, s12 bold | |
ImageButton.SetGuiColor("White") | |
; “标题栏”图标 | |
; Gui, Add, Text, w25 h25 0x3 0x200 hwndhPic | |
; if DllCall("PrivateExtractIcons", "Str",A_ScriptFullPath, "Int",0, "Int",16, "Int",16, "PtrP",hicon, "UInt",0, "UInt",1, "UInt",0) | |
; SendMessage, 0x0170, hIcon, 0,, Ahk_ID %hPic% | |
Gui, Add, Picture, Icon1 x5 y5 w16 h16, % A_IsCompiled ? A_ScriptFullPath : A_AhkPath | |
Gui, Add, Text, xp-5 y0 BackgroundTrans w371 h25 Center 0x200, 北京时间校准器 | |
Gui, Font, s12, Marlett | |
Gui, Add, Button, xp+310 w32 h25 hwndHBT gGuiMinimize, 0 | |
Opt1 := [0, 0xFFFFFF,, 0xCCCCCC] | |
Opt2 := [ , 0xEEEEEE,, "Black"] | |
Opt3 := [ , 0x4EA6EA,, "White"] | |
ImageButton.Create(HBT, Opt1, Opt2, Opt3) | |
Gui, Add, Button, x+0 w29 hp gGuiClose hwndHBT, r | |
Opt1 := [0, 0xFFFFFF,, 0xCCCCCC] | |
Opt2 := [ , 0xE04343,, "White"] | |
Opt3 := [ , 0x993D3D,, "White"] | |
ImageButton.Create(HBT, Opt1, Opt2, Opt3) | |
Gui, Font | |
Gui, Font, s12 bold | |
Gui, Add, Text, xm-2 w375 h4 +E0x200 | |
Gui, Add, Text, xm+51 yp+30 w200 c716F64 Section vtxt1, 标准时间: | |
Gui, Add, Text, xs w230 h90 hwndhText1 vhh_mm, 00:00 | |
CustomFont.AddFromResource(hText1, "wwDigital.ttf", "WW Digital", 100, hFont1) | |
Gui, Add, Text, x+0 yp+45 w50 h40 hwndhText2 vss, 00 | |
CustomFont.AddFromResource(hText2, "wwDigital.ttf", "WW Digital", 40, hFont2) | |
Gui, Add, Text, xs 0x10 w270 h1 ; 分割线 | |
Gui, Add, Text, xs+5 y+5 wp-10 h20 Right hwndhText3 vyyyy_mm_dd, 0000 - 00 - 00 | |
CustomFont.AddFromResource(hText3, "wwDigital.ttf", "WW Digital", 20, hFont3) | |
Gui, Add, Text, xs y+10 c716F64, 电脑时间: | |
Gui, Add, Text, x+10 w150 v_status Hidden cRed, (校对中...) | |
Gui, Add, Text, xs+50 y+15 vLocalTime, %A_YYYY%-%A_Mon%-%A_DD% %A_Hour%:%A_Min%:%A_Sec% | |
Gui, Add, Button, xs y+30 w270 h40 hwndHBT Disabled vbtn_JiaoDui gbtn_JiaoDui, 校 对 | |
Opt1 := [3, 0x00B700, 0x009F00, 0xFFFFFF, 5] | |
Opt2 := [3, 0x80FF80, 0x00B700, 0xFFFFFF, 5] | |
Opt4 := [3, 0xCACBC2, 0xCACBC2, 0x6E6E6E, 5] | |
ImageButton.Create(HBT, Opt1, Opt2,, Opt4) | |
Gui, Show, w371 h340 | |
GuiControl, Focus, txt1 | |
OnMessage(0x0201, "WM_LBUTTONDOWN") ; 左键拖拽界面 | |
SetTimer, UpdateTime, 1000 | |
Goto, GetBeijingTime | |
Return | |
; ================================= | |
; 获取标准时间 | |
; ================================= | |
GetBeijingTime: | |
GuiControl, +cRed, txt1 | |
GuiControl,, txt1, 正在获取标准时间... | |
BeijingTime := GetBeijingTime() ; 从 http://open.baidu.com/special/time/ 获取标准时间 | |
GuiControl, +c716F64, txt1 | |
GuiControl,, txt1, 标准时间: | |
GuiControl, Enable, btn_JiaoDui | |
Return | |
; ================================= | |
; 更新界面时间 | |
; ================================= | |
UpdateTime: | |
; 更新界面上的“电脑时间” | |
GuiControl,, LocalTime, %A_YYYY%-%A_Mon%-%A_DD% %A_Hour%:%A_Min%:%A_Sec% | |
; 如果还没有获取到标准时间则返回 | |
if !BeijingTime | |
Return | |
; ================================= | |
; 更新界面上的“标准时间” | |
; ================================= | |
BeijingTime += 1, Seconds | |
FormatTime, yyyy_mm_dd, %BeijingTime%, yyyy - MM - dd | |
FormatTime, hh_mm, %BeijingTime%, HH:mm | |
FormatTime, ss, %BeijingTime%, ss | |
; <小时:分钟> 和上次不同时,才更新界面中的 <小时:分钟> | |
if ( hh_mm != Last_hh_mm ) | |
GuiControl,, hh_mm, % Last_hh_mm := hh_mm | |
; 更新 <秒钟> | |
GuiControl,, ss, % Last_ss := ss | |
; <日期> 和上次不同时,才更新界面中的 <日期> | |
if ( yyyy_mm_dd != Last_yyyy_mm_dd ) | |
GuiControl,, yyyy_mm_dd, % Last_yyyy_mm_dd := yyyy_mm_dd | |
Return | |
; ================================= | |
; 校 对 | |
; ================================= | |
btn_JiaoDui: | |
; 禁用【校对】按钮 | |
GuiControl, Disable, btn_JiaoDui | |
; 显示校对状态 | |
GuiControl, +cRed, _status | |
GuiControl,, _status, (校对中...) | |
GuiControl, Show, _status | |
; 设置系统时间 | |
SetLocalTime(BeijingTime) | |
; 启用【校对】按钮 | |
GuiControl, Enable, btn_JiaoDui | |
; 修改校对状态 | |
GuiControl, +c00B700, _status | |
GuiControl,, _status, (校对完毕!) | |
; 3 秒后隐藏校对状态 | |
SetTimer, HideStatus, -3000 | |
Return | |
; 隐藏校对状态 | |
HideStatus: | |
GuiControl, Hide, _status | |
Return | |
; 移除托盘提示 | |
RemoveTrayTip: | |
TrayTip | |
Return | |
; 最小化按钮 | |
GuiMinimize: | |
Gui, Minimize | |
Return | |
; 关闭按钮 | |
GuiClose: | |
ExitApp | |
ExitSub: | |
CustomFont.Remove() | |
ExitApp | |
; ============================================================================== | |
UrlDownloadToVar(Url, ByRef Result, Timeout = -1) ; Return: Success = -1, Timeout = 0, No response = Empty String | |
{ | |
static e := ComObjError(0) | |
static WinHttpReq := ComObjCreate("WinHttp.WinHttpRequest.5.1") | |
WinHttpReq.Open("GET", Url, True) | |
WinHttpReq.SetRequestHeader( "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)" ) | |
WinHttpReq.Send() | |
Return WinHttpReq.WaitForResponse(Timeout), Result := WinHttpReq.ResponseText | |
} | |
unix2Human(unixTimestamp) | |
{ | |
_date = 1970010108 | |
_date += unixTimestamp, s | |
return _date | |
} | |
GetBeijingTime() | |
{ | |
While, !UrlDownloadToVar("http://open.baidu.com/special/time/", html) | |
Sleep, 1000 | |
if !RegExMatch( html, "i)window\.baidu_time\(\K\d+", unixTimestamp ) | |
Return False | |
unixTimestamp := SubStr(unixTimestamp, 1, 10) | |
BeijingTime := unix2Human(unixTimestamp) | |
Return BeijingTime | |
} | |
SetLocalTime(YYYYMMDDHH24MISS) | |
{ | |
VarSetCapacity(newtime, 16, 0) | |
For i, n in [ [0,1,4],[2,5,2],[6,7,2],[8,9,2],[10,11,2],[12,13,2],[14,15,3] ] | |
NumPut( SubStr(YYYYMMDDHH24MISS, n.2, n.3), newtime, n.1, "UShort" ) | |
DllCall("SetLocalTime", "Ptr", &newtime) | |
} | |
WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) { | |
global hGui | |
If (hwnd = hGui) | |
PostMessage, 0xA1, 2 ; WM_NCLBUTTONDOWN | |
} | |
FileInstall, wwDigital.ttf, - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment