-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmNtp.frm
More file actions
339 lines (314 loc) · 9.5 KB
/
Copy pathfrmNtp.frm
File metadata and controls
339 lines (314 loc) · 9.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
'#Region "Form"
#if defined(__FB_MAIN__) AndAlso Not defined(__MAIN_FILE__)
#define __MAIN_FILE__
#ifdef __FB_WIN32__
#cmdline "frmNtp.rc"
#endif
Const _MAIN_FILE_ = __FILE__
#endif
#include once "mff/Form.bi"
#include once "mff/ComboBoxEdit.bi"
#include once "mff/ComboBoxEx.bi"
#include once "mff/Label.bi"
#include once "mff/CommandButton.bi"
#include once "mff/ListView.bi"
#include once "mff/ImageList.bi"
#include once "../PipeProcess/PipeProcess.bi"
#include once "frmTimezone.frm"
Using My.Sys.Forms
Type frmNtpType Extends Form
mPp As PipeProcess
mTzBias As Integer
Declare Sub Form_Create(ByRef Sender As Control)
Declare Sub Form_Destroy(ByRef Sender As Control)
Declare Sub ComboBoxEx1_Selected(ByRef Sender As ComboBoxEdit, ItemIndex As Integer)
Declare Sub CommandButton_Click(ByRef Sender As Control)
Declare Constructor
Dim As ComboBoxEx ComboBoxEx1
Dim As CommandButton CommandButton1, CommandButton2, CommandButton3, CommandButton4
Dim As ListView ListView1
Dim As ImageList ImageList1
NTPName(32) As String = { _
"中国时间服务器", _
"中国国家授时中心", _
"上海交通大学网络中心NTP服务器地址", _
"北京邮电大学", _
"清华大学", _
"北京大学", _
"东南大学", _
"清华大学", _
"清华大学", _
"清华大学", _
"北京邮电大学", _
"西南地区网络中心", _
"西北地区网络中心", _
"东北地区网络中心", _
"华东南地区网络中心", _
"四川大学网络管理中心", _
"大连理工大学网络中心", _
"CERNET桂林主节点", _
"北京大学", _
"NIST, Gaithersburg, Maryland", _
"NIST, Gaithersburg, Maryland", _
"NIST, Boulder, Colorado", _
"NIST, Boulder, Colorado", _
"NIST, Boulder, Colorado", _
"University of Colorado, Boulder", _
"NCAR, Boulder, Colorado", _
"Microsoft, Redmond, Washington", _
"Symmetricom, San Jose, California", _
"Abovenet, Virginia", _
"Abovenet, New York City", _
"Abovenet, San Jose, California", _
"TrueTime, AOL facility, Sunnyvale, California", _
"TrueTime, AOL facility, Virginia" _
}
NTPAddress(32) As String = { _
"cn.pool.ntp.org", _
"ntp.ntsc.ac.cn", _
"ntp.sjtu.edu.cn", _
"s1a.time.edu.cn", _
"s1b.time.edu.cn", _
"s1c.time.edu.cn", _
"s1d.time.edu.cn", _
"s1e.time.edu.cn", _
"s2a.time.edu.cn", _
"s2b.time.edu.cn", _
"s2c.time.edu.cn", _
"s2d.time.edu.cn", _
"s2e.time.edu.cn", _
"s2f.time.edu.cn", _
"s2g.time.edu.cn", _
"s2h.time.edu.cn", _
"s2j.time.edu.cn", _
"s2k.time.edu.cn", _
"s2m.time.edu.cn", _
"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", _
"time-nw.nist.gov", _
"nist1.symmetricom.com", _
"nist1-dc.glassey.com", _
"nist1-ny.glassey.com", _
"nist1-sj.glassey.com", _
"nist1.aol-ca.truetime.com", _
"nist1.aol-va.truetime.com" _
}
Dim As Label Label1
End Type
Constructor frmNtpType
' frmNtp
With This
.Name = "frmNtp"
.Text = "Network Time Protocol Client"
.Designer = @This
.Caption = "Network Time Protocol Client"
.StartPosition = FormStartPosition.CenterScreen
.OnCreate = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @Form_Create)
.OnDestroy = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @Form_Destroy)
.BorderStyle = FormBorderStyle.FixedSingle
.MaximizeBox = False
.SetBounds 0, 0, 325, 340
End With
' ComboBoxEx1
With ComboBoxEx1
.Name = "ComboBoxEx1"
.Text = "ComboBoxEx1"
.TabIndex = 0
.ImagesList = @ImageList1
.SetBounds 20, 20, 280, 22
.Designer = @This
.Parent = @This
Dim i As Integer
For i = 0 To 32
.OnSelected = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As ComboBoxEdit, ItemIndex As Integer), @ComboBoxEx1_Selected)
.Items.Add(NTPName(i), , 13, 13, 13)
Next
End With
' Label1
With Label1
.Name = "Label1"
.Text = ""
.TabIndex = 1
.Caption = ""
.SetBounds 20, 60, 280, 20
.Designer = @This
.Parent = @This
End With
' ListView1
With ListView1
.Name = "ListView1"
.Text = "ListView1"
.TabIndex = 2
.SmallImages = @ImageList1
.Images = @ImageList1
.SetBounds 20, 90, 280, 140
.Designer = @This
.Parent = @This
.Columns.Add("Item", 0 , 100)
.Columns.Add("Desc", 0 , .Width - 105)
.ListItems.Add("Server", 13)
.ListItems.Add("Address", 18)
.ListItems.Add("Timezone bias", 21)
.ListItems.Add("Host", 20)
.ListItems.Add("Local", 15)
.ListItems.Add("Result", 17)
End With
' CommandButton1
With CommandButton1
.Name = "CommandButton1"
.Text = "Date Time"
.TabIndex = 3
.Caption = "Date Time"
.SetBounds 20, 250, 100, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton_Click)
.Parent = @This
End With
' CommandButton2
With CommandButton2
.Name = "CommandButton2"
.Text = "Timezone"
.TabIndex = 4
.Caption = "Timezone"
.SetBounds 20, 280, 100, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton_Click)
.Parent = @This
End With
' CommandButton3
With CommandButton3
.Name = "CommandButton3"
.Text = "Check"
.TabIndex = 5
.Caption = "Check"
.SetBounds 200, 250, 100, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton_Click)
.Parent = @This
End With
' CommandButton4
With CommandButton4
.Name = "CommandButton4"
.Text = "Calibrate"
.TabIndex = 6
.Caption = "Calibrate"
.SetBounds 200, 280, 100, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton_Click)
.Parent = @This
End With
' ImageList1
With ImageList1
.Name = "ImageList1"
.SetBounds 20, 210, 16, 16
.Designer = @This
.Parent = @This
End With
End Constructor
Dim Shared frmNtp As frmNtpType
#if _MAIN_FILE_ = __FILE__
App.DarkMode = True
frmNtp.MainForm = True
frmNtp.Show
App.Run
#endif
'#End Region
#include once "ntp.bi"
Private Sub frmNtpType.Form_Create(ByRef Sender As Control)
Dim i As Long
Dim j As Long
Dim Icon As HICON
j = ExtractIconEx("C:\Windows\System32\shell32.dll", -1, 0, 0, 1)
For i = 0 To j
ExtractIconEx "C:\Windows\System32\shell32.dll", i, 0, @Icon, 1
ImageList_ReplaceIcon(ImageList1.Handle, -1, Icon)
DestroyIcon Icon
Next
ComboBoxEx1.ItemIndex = 0
ComboBoxEx1_Selected(ComboBoxEx1, 0)
Dim pTimeZoneInformation As PDYNAMIC_TIME_ZONE_INFORMATION = New DYNAMIC_TIME_ZONE_INFORMATION
GetDynamicTimeZoneInformation(pTimeZoneInformation)
mTzBias = pTimeZoneInformation->Bias
Label1.Caption = "Timezone: " & pTimeZoneInformation->TimeZoneKeyName & ", " & mTzBias
ListView1.ListItems.Item(2)->Text(1) = Format(mTzBias, "0")
End Sub
Private Sub frmNtpType.Form_Destroy(ByRef Sender As Control)
End Sub
Private Sub frmNtpType.ComboBoxEx1_Selected(ByRef Sender As ComboBoxEdit, ItemIndex As Integer)
ListView1.ListItems.Item(0)->Text(1) = NTPName(ItemIndex)
ListView1.ListItems.Item(1)->Text(1) = NTPAddress(ItemIndex)
End Sub
Private Sub frmNtpType.CommandButton_Click(ByRef Sender As Control)
Select Case Sender.Name
Case "CommandButton1"
Dim rtns As WString * 1024
mPp.PipeCreate(@This, "rundll32.exe shell32.dll,Control_RunDLL timedate.cpl,,0", rtns)
Case "CommandButton2"
Dim a As frmTinezoneType Ptr = New frmTinezoneType
a->ShowModal This
Case "CommandButton3"
If Sender.Text = "Check" Then
Sender.Text = "Cancel"
CommandButton4.Enabled = False
Dim t As Double = NTP_dbl(NTP_sec(NTPAddress(ComboBoxEx1.ItemIndex)), mTzBias)
If ntpCancel Then
ListView1.ListItems.Item(3)->Text(1) = ""
ListView1.ListItems.Item(4)->Text(1) = ""
ListView1.ListItems.Item(5)->Text(1) = "Cancel"
Else
Dim n As Double = Now()
ListView1.ListItems.Item(3)->Text(1) = Format(t, "yyyy/mm/dd hh:mm:ss")
ListView1.ListItems.Item(4)->Text(1) = Format(n, "yyyy/mm/dd hh:mm:ss")
If t = n Then
ListView1.ListItems.Item(5)->Text(1) = "Check Passed"
Else
ListView1.ListItems.Item(5)->Text(1) = "Check Failed"
End If
End If
Sender.Text = "Check"
CommandButton4.Enabled = True
Else
ntpCancel = True
End If
Case "CommandButton4"
If Sender.Text = "Calibrate" Then
Sender.Text = "Cancel"
CommandButton3.Enabled = False
Print ProcessToken(@SE_SYSTEMTIME_NAME)
Dim t As Double = NTP_dbl(NTP_sec(NTPAddress(ComboBoxEx1.ItemIndex)), 0)
If ntpCancel Then
ListView1.ListItems.Item(3)->Text(1) = ""
ListView1.ListItems.Item(4)->Text(1) = ""
ListView1.ListItems.Item(5)->Text(1) = "Cancel"
Else
Dim st As SYSTEMTIME Ptr = New SYSTEMTIME
st->wYear = Year(t)
st->wMonth = Month(t)
st->wDay = Day(t)
st->wHour = Hour(t)
st->wMinute= Minute(t)
st->wSecond = Second(t)
Dim b As Boolean = SetSystemTime(st)
t = NTP_dbl(NTP_sec(NTPAddress(ComboBoxEx1.ItemIndex)), mTzBias)
Dim n As Double = Now()
ListView1.ListItems.Item(3)->Text(1) = Format(t, "yyyy/mm/dd hh:mm:ss")
ListView1.ListItems.Item(4)->Text(1) = Format(n, "yyyy/mm/dd hh:mm:ss")
If b Then
ListView1.ListItems.Item(5)->Text(1) = "Calibrate Passed"
Else
ListView1.ListItems.Item(5)->Text(1) = "Calibrate Failed"
MsgRunAs
End If
End If
Sender.Text = "Calibrate"
CommandButton3.Enabled = True
Else
ntpCancel = True
End If
End Select
End Sub