2 * PROJECT: ReactOS Timedate Control Panel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/timedate/internettime.c
5 * PURPOSE: Internet Time property page
6 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
13 DWORD WINAPI
W32TimeSyncNow(LPCWSTR cmdline
, UINT blocking
, UINT flags
);
16 CreateNTPServerList(HWND hwnd
)
19 WCHAR szValName
[MAX_VALUE_NAME
];
28 hList
= GetDlgItem(hwnd
,
31 lRet
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
32 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
36 if (lRet
!= ERROR_SUCCESS
)
41 dwValSize
= MAX_VALUE_NAME
* sizeof(WCHAR
);
43 lRet
= RegEnumValueW(hKey
,
51 if (lRet
== ERROR_SUCCESS
)
53 /* Get date from default reg value */
54 if (wcscmp(szValName
, L
"") == 0) // if (Index == 0)
56 dwDefault
= _wtoi(szData
);
68 else if (lRet
!= ERROR_MORE_DATA
)
74 if (dwDefault
< 1 || dwDefault
> dwIndex
)
77 /* Server reg entries count from 1,
78 * Combo boxes count from 0 */
90 /* Set the selected server in the registry */
92 SetNTPServer(HWND hwnd
)
101 hList
= GetDlgItem(hwnd
,
104 uSel
= (UINT
)SendMessageW(hList
, CB_GETCURSEL
, 0, 0);
106 SendDlgItemMessageW(hwnd
, IDC_SERVERLIST
, WM_GETTEXT
, _countof(buffer
), (LPARAM
)buffer
);
108 /* If there is new data entered then save it in the registry
109 The same key name of "0" is used to store all user entered values
113 lRet
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
114 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
118 if (lRet
!= ERROR_SUCCESS
)
120 DisplayWin32Error(lRet
);
123 lRet
= RegSetValueExW(hKey
,
128 (wcslen(buffer
) + 1) * sizeof(WCHAR
));
129 if (lRet
!= ERROR_SUCCESS
)
130 DisplayWin32Error(lRet
);
133 /* Server reg entries count from 1,
134 * Combo boxes count from 0 */
137 /* Convert to wide char */
138 _itow(uSel
, szSel
, 10);
140 lRet
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
141 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
145 if (lRet
!= ERROR_SUCCESS
)
147 DisplayWin32Error(lRet
);
151 lRet
= RegSetValueExW(hKey
,
156 (wcslen(szSel
) + 1) * sizeof(WCHAR
));
157 if (lRet
!= ERROR_SUCCESS
)
158 DisplayWin32Error(lRet
);
165 EnableDialogText(HWND hwnd
)
170 uCheck
= (UINT
)SendDlgItemMessageW(hwnd
, IDC_AUTOSYNC
, BM_GETCHECK
, 0, 0);
171 bChecked
= (uCheck
== BST_CHECKED
) ? TRUE
: FALSE
;
173 EnableWindow(GetDlgItem(hwnd
, IDC_SERVERTEXT
), bChecked
);
174 EnableWindow(GetDlgItem(hwnd
, IDC_SERVERLIST
), bChecked
);
175 EnableWindow(GetDlgItem(hwnd
, IDC_UPDATEBUTTON
), bChecked
);
176 EnableWindow(GetDlgItem(hwnd
, IDC_SUCSYNC
), bChecked
);
177 EnableWindow(GetDlgItem(hwnd
, IDC_NEXTSYNC
), bChecked
);
182 GetSyncSetting(HWND hwnd
)
188 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
189 L
"SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters",
192 &hKey
) == ERROR_SUCCESS
)
194 dwSize
= 8 * sizeof(WCHAR
);
195 if (RegQueryValueExW(hKey
,
200 &dwSize
) == ERROR_SUCCESS
)
202 if (wcscmp(szData
, L
"NTP") == 0)
203 SendDlgItemMessageW(hwnd
, IDC_AUTOSYNC
, BM_SETCHECK
, BST_CHECKED
, 0);
205 SendDlgItemMessageW(hwnd
, IDC_AUTOSYNC
, BM_SETCHECK
, BST_UNCHECKED
, 0);
214 OnInitDialog(HWND hwnd
)
216 GetSyncSetting(hwnd
);
217 EnableDialogText(hwnd
);
218 CreateNTPServerList(hwnd
);
222 OnAutoSync(BOOL Sync
)
233 lRet
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
234 L
"SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters",
238 if (lRet
!= ERROR_SUCCESS
)
240 DisplayWin32Error(lRet
);
244 lRet
= RegSetValueExW(hKey
,
249 (wcslen(szAuto
) + 1) * sizeof(WCHAR
));
250 if (lRet
!= ERROR_SUCCESS
)
251 DisplayWin32Error(lRet
);
256 /* Property page dialog callback */
258 InetTimePageProc(HWND hwndDlg
,
266 OnInitDialog(hwndDlg
);
270 switch(LOWORD(wParam
))
272 case IDC_UPDATEBUTTON
:
276 SetNTPServer(hwndDlg
);
278 dwError
= W32TimeSyncNow(L
"localhost", 0, 0);
279 if (dwError
!= ERROR_SUCCESS
)
281 DisplayWin32Error(dwError
);
287 if ((HIWORD(wParam
) == CBN_SELCHANGE
) || (HIWORD(wParam
) == CBN_EDITCHANGE
))
289 /* Enable the 'Apply' button */
290 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
295 if (HIWORD(wParam
) == BN_CLICKED
)
297 EnableDialogText(hwndDlg
);
299 /* Enable the 'Apply' button */
300 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
311 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
316 SetNTPServer(hwndDlg
);
318 if (SendDlgItemMessageW(hwndDlg
, IDC_AUTOSYNC
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)