?? frmmain.frm
字號(hào):
VERSION 5.00
Begin VB.Form frmMain
BorderStyle = 0 'None
Caption = "網(wǎng)絡(luò)時(shí)間同步"
ClientHeight = 3615
ClientLeft = 3810
ClientTop = 3900
ClientWidth = 5610
Icon = "frmMain.frx":0000
LinkTopic = "Form1"
ScaleHeight = 3615
ScaleWidth = 5610
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin Project1.Socket Winsock1
Left = 120
Top = 2400
_ExtentX = 741
_ExtentY = 741
End
Begin VB.Timer get_time
Interval = 60000
Left = 120
Top = 2880
End
Begin VB.Menu mSysPopup
Caption = "SysPopup"
Begin VB.Menu mTimeSyn
Caption = "立即同步"
End
Begin VB.Menu mOption
Caption = "系統(tǒng)設(shè)置"
End
Begin VB.Menu mSep1
Caption = "-"
End
Begin VB.Menu mExit
Caption = "退出程序"
End
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim mtime_zone$ '時(shí)區(qū)
Dim mblnFlag As Boolean '同步時(shí)間標(biāo)志
Private Sub Form_Resize()
If Me.WindowState = vbMinimized Then Me.Hide
End Sub
Private Sub Form_Load()
frmMain.Hide
Set iniOp = New clsIniOp
With iniOp
.Inipath = App.Path & "\Config.ini" '指定路徑
strServer = .Getstr("Options", "TimeServer", "time-nw.nist.gov")
valTimer = .Getstr("Options", "SynTimer", "1")
End With
With NotifyIcon
.cbSize = Len(NotifyIcon)
.dwInfoFlags = NIIF_INFO
.hIcon = Me.Icon.Handle
.hWnd = Me.hWnd
.szInfoTitle = "同步網(wǎng)絡(luò)時(shí)間" & vbNullChar
.szInfo = "正在連接時(shí)間服務(wù)器,請(qǐng)稍候..." & vbNullChar
.uCallBackMessage = WM_NOTIFYICON
.uFlags = NIF_ICON Or NIF_INFO Or NIF_MESSAGE Or NIF_TIP
End With
Shell_NotifyIcon NIM_ADD, NotifyIcon
pWndProc = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WndProc)
Call synchMyTime
End Sub
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, NotifyIcon
SetWindowLong Me.hWnd, GWL_WNDPROC, pWndProc
Set iniOp = Nothing
End Sub
Private Sub get_time_Timer()
Static s_Minutes As Long
s_Minutes = s_Minutes + 1
If s_Minutes = valTimer Then
s_Minutes = 0
Call synchMyTime
End If
End Sub
Private Sub mExit_Click()
Unload Me
End Sub
Private Sub mOption_Click()
frmOption.Show
End Sub
Private Sub mTimeSyn_Click()
Call synchMyTime
End Sub
'數(shù)據(jù)到達(dá)事件
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data As String, tmpChar$, Mydate$
'獲得服務(wù)器數(shù)據(jù)
Winsock1.GetData data
'判斷是否同步時(shí)間
If mblnFlag Then
'服務(wù)器數(shù)據(jù)結(jié)構(gòu)中第17,18位為小時(shí),第20,21,22,23,24位為分鐘和秒鐘
tmpChar$ = Val(Mid$(data, 17, 2) + 8)
'同步標(biāo)準(zhǔn)時(shí)間
Time = tmpChar$ + ":" + Mid$(data, 20, 5)
Mydate$ = Mid$(data, 8, 8)
Date = Mydate$
mblnFlag = False
NotifyIcon.szInfoTitle = "同步網(wǎng)絡(luò)時(shí)間" & vbNullChar
NotifyIcon.szInfo = "同步成功,服務(wù)器時(shí)間:" & Format(Mydate$, "yyyy-mm-dd") & _
" " & tmpChar$ + ":" + Mid$(data, 20, 5) & vbNullChar
Shell_NotifyIcon NIM_MODIFY, NotifyIcon
End If
'斷開(kāi)遠(yuǎn)程連接
Winsock1.CloseSck
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal sCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
NotifyIcon.szInfoTitle = "同步網(wǎng)絡(luò)時(shí)間" & vbNullChar
NotifyIcon.szInfo = "同步失敗,請(qǐng)檢查網(wǎng)絡(luò)連接!" & vbNullChar
Shell_NotifyIcon NIM_MODIFY, NotifyIcon
Winsock1.CloseSck '關(guān)閉以前的連接
mblnFlag = False
End Sub
Public Sub synchMyTime()
Dim mserverName$ '時(shí)間服務(wù)器
mserverName = strServer '超快響應(yīng)
If mblnFlag = False Then
'連接服務(wù)器
Winsock1.Connect mserverName, 13 '時(shí)間端口號(hào)為13
mblnFlag = True
End If
End Sub
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -