mirror of
https://github.com/reactos/reactos.git
synced 2024-10-04 08:25:53 +00:00
- Add an analog clock to the timedate cpl.
- Add more code towards setting system time via NTP svn path=/trunk/; revision=21218
This commit is contained in:
parent
7dac3e7a17
commit
c280bc696c
|
@ -15,7 +15,7 @@ BEGIN
|
|||
GROUPBOX "&Time", -1, 132, 2, 113, 125
|
||||
CONTROL "", IDC_TIMEPICKER, "SysDateTimePick32",
|
||||
DTS_TIMEFORMAT | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
|
||||
144, 17, 90, 12
|
||||
144, 105, 90, 12
|
||||
LTEXT "", IDC_TIMEZONE, 4, 136, 241, 8
|
||||
END
|
||||
|
||||
|
@ -38,9 +38,9 @@ CAPTION "Internet Time"
|
|||
FONT 8, "MS Shell Dlg", 0, 0, 0x0
|
||||
BEGIN
|
||||
COMBOBOX IDC_SERVERLIST, 65, 22, 117, 136, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
CONTROL "Automatically synchronize with an Internet time server", IDC_AUTOSYNC,
|
||||
"Button", BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP, 11 ,7, 241, 10
|
||||
LTEXT "Server:", -1, 34, 22, 28, 13
|
||||
AUTOCHECKBOX "Automatically synchronize with an Internet time server", IDC_AUTOSYNC,
|
||||
11 ,7, 241, 10, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
|
||||
LTEXT "Server:", IDC_SERVERTEXT, 34, 22, 28, 13
|
||||
PUSHBUTTON "Update Now", IDC_UPDATEBUTTON, 187, 22, 49, 14
|
||||
LTEXT "", IDC_SUCSYNC, 12, 54, 214, 23
|
||||
LTEXT "", IDC_NEXTSYNC, 12, 96, 137, 12
|
||||
|
|
174
reactos/dll/cpl/timedate/clock.c
Normal file
174
reactos/dll/cpl/timedate/clock.c
Normal file
|
@ -0,0 +1,174 @@
|
|||
/* Core functions lifted from Programming Windows, Charles Petzold */
|
||||
|
||||
#include "timedate.h"
|
||||
|
||||
#define TWOPI (2 * 3.14159)
|
||||
|
||||
static const TCHAR szClockWndClass[] = TEXT("ClockWndClass");
|
||||
|
||||
|
||||
VOID SetIsotropic(HDC hdc, INT cxClient, INT cyClient)
|
||||
{
|
||||
SetMapMode (hdc, MM_ISOTROPIC);
|
||||
SetWindowExtEx (hdc, 1000, 1000, NULL);
|
||||
SetViewportExtEx (hdc, cxClient / 2, -cyClient / 2, NULL);
|
||||
SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL);
|
||||
}
|
||||
|
||||
VOID RotatePoint(POINT pt[], INT iNum, INT iAngle)
|
||||
{
|
||||
INT i;
|
||||
POINT ptTemp;
|
||||
|
||||
for (i = 0 ; i < iNum ; i++)
|
||||
{
|
||||
ptTemp.x = (INT) (pt[i].x * cos (TWOPI * iAngle / 360) +
|
||||
pt[i].y * sin (TWOPI * iAngle / 360));
|
||||
|
||||
ptTemp.y = (INT) (pt[i].y * cos (TWOPI * iAngle / 360) -
|
||||
pt[i].x * sin (TWOPI * iAngle / 360));
|
||||
|
||||
pt[i] = ptTemp;
|
||||
}
|
||||
}
|
||||
|
||||
VOID DrawClock(HDC hdc)
|
||||
{
|
||||
INT iAngle;
|
||||
POINT pt[3];
|
||||
|
||||
for (iAngle = 0; iAngle < 360; iAngle += 6)
|
||||
{
|
||||
pt[0].x = 0;
|
||||
pt[0].y = 900;
|
||||
|
||||
RotatePoint(pt, 1, iAngle);
|
||||
|
||||
pt[2].x = pt[2].y = iAngle % 5 ? 33 : 100;
|
||||
|
||||
pt[0].x -= pt[2].x / 2;
|
||||
pt[0].y -= pt[2].y / 2;
|
||||
|
||||
pt[1].x = pt[0].x + pt[2].x;
|
||||
pt[1].y = pt[0].y + pt[2].y;
|
||||
|
||||
SelectObject(hdc, GetStockObject (BLACK_BRUSH));
|
||||
|
||||
Ellipse(hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
|
||||
}
|
||||
}
|
||||
|
||||
VOID DrawHands(HDC hdc, SYSTEMTIME * pst, BOOL fChange)
|
||||
{
|
||||
static POINT pt[3][5] = { {{0, -150}, {100, 0}, {0, 600}, {-100, 0}, {0, -150}},
|
||||
{{0, -200}, { 50, 0}, {0, 800}, { -50, 0}, {0, -200}},
|
||||
{{0, 0}, { 0, 0}, {0, 0}, { 0, 0}, {0, 800}} };
|
||||
INT i, iAngle[3];
|
||||
POINT ptTemp[3][5];
|
||||
|
||||
iAngle[0] = (pst->wHour * 30) % 360 + pst->wMinute / 2;
|
||||
iAngle[1] = pst->wMinute * 6;
|
||||
iAngle[2] = pst->wSecond * 6;
|
||||
|
||||
memcpy(ptTemp, pt, sizeof(pt));
|
||||
|
||||
for (i = fChange ? 0 : 2 ; i < 3 ; i++)
|
||||
{
|
||||
RotatePoint(ptTemp[i], 5, iAngle[i]);
|
||||
|
||||
Polygon(hdc, ptTemp[i], 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static LRESULT CALLBACK
|
||||
ClockWndProc(HWND hwnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
static INT cxClient, cyClient;
|
||||
static SYSTEMTIME stPrevious;
|
||||
BOOL fChange;
|
||||
HDC hdc;
|
||||
PAINTSTRUCT ps;
|
||||
SYSTEMTIME st;
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_CREATE:
|
||||
SetTimer(hwnd, ID_TIMER, 1000, NULL);
|
||||
GetLocalTime(&st);
|
||||
stPrevious = st;
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
cxClient = LOWORD(lParam);
|
||||
cyClient = HIWORD(lParam);
|
||||
break;
|
||||
|
||||
case WM_TIMER:
|
||||
GetLocalTime(&st);
|
||||
|
||||
fChange = st.wHour != stPrevious.wHour ||
|
||||
st.wMinute != stPrevious.wMinute;
|
||||
|
||||
hdc = GetDC(hwnd);
|
||||
|
||||
SetIsotropic(hdc, cxClient, cyClient);
|
||||
|
||||
InvalidateRect(hwnd, NULL, TRUE);
|
||||
|
||||
SelectObject(hdc, GetStockObject(BLACK_PEN));
|
||||
DrawHands(hdc, &st, TRUE);
|
||||
|
||||
ReleaseDC(hwnd, hdc);
|
||||
|
||||
stPrevious = st;
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
hdc = BeginPaint(hwnd, &ps);
|
||||
|
||||
SetIsotropic(hdc, cxClient, cyClient);
|
||||
|
||||
DrawClock(hdc);
|
||||
SelectObject(hdc, GetStockObject(WHITE_BRUSH));
|
||||
DrawHands(hdc, &stPrevious, TRUE);
|
||||
|
||||
EndPaint(hwnd, &ps);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
KillTimer(hwnd, ID_TIMER);
|
||||
break;
|
||||
|
||||
default:
|
||||
DefWindowProc(hwnd,
|
||||
uMsg,
|
||||
wParam,
|
||||
lParam);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOL
|
||||
InitClockWindowClass(VOID)
|
||||
{
|
||||
WNDCLASSEX wc = {0};
|
||||
|
||||
wc.cbSize = sizeof(WNDCLASSEX);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = ClockWndProc;
|
||||
wc.hInstance = hApplet;
|
||||
wc.hIcon = NULL;
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
||||
wc.lpszClassName = szClockWndClass;
|
||||
wc.hIconSm = NULL;
|
||||
|
||||
return RegisterClassEx(&wc) != (ATOM)0;
|
||||
}
|
87
reactos/dll/cpl/timedate/ntpclient.c
Normal file
87
reactos/dll/cpl/timedate/ntpclient.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include "timedate.h"
|
||||
|
||||
SOCKET Sock;
|
||||
SOCKADDR_IN myAddr, ntpAddr;
|
||||
|
||||
BOOL InitialiseConnection()
|
||||
{
|
||||
WSADATA wsaData;
|
||||
INT Ret;
|
||||
|
||||
Ret = WSAStartup(MAKEWORD(2, 2),
|
||||
&wsaData);
|
||||
if (Ret != 0)
|
||||
return FALSE;
|
||||
|
||||
|
||||
Sock = WSASocket(AF_INET,
|
||||
SOCK_DGRAM,
|
||||
IPPROTO_UDP,
|
||||
NULL,
|
||||
0,
|
||||
WSA_FLAG_OVERLAPPED);
|
||||
if (Sock == INVALID_SOCKET )
|
||||
return FALSE;
|
||||
|
||||
/* setup client socket */
|
||||
ZeroMemory(&myAddr, sizeof(myAddr));
|
||||
myAddr.sin_family = AF_INET;
|
||||
myAddr.sin_port = htons(IPPORT_TIMESERVER);
|
||||
myAddr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
Ret = bind(Sock,
|
||||
(SOCKADDR *)&myAddr,
|
||||
sizeof(SOCKADDR));
|
||||
if (Ret == SOCKET_ERROR)
|
||||
return FALSE;
|
||||
|
||||
/* setup server socket */
|
||||
ZeroMemory(&ntpAddr, sizeof(ntpAddr));
|
||||
ntpAddr.sin_family = AF_INET;
|
||||
ntpAddr.sin_port = htons(IPPORT_TIMESERVER);
|
||||
ntpAddr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VOID DestroyConnection()
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
/* send some data to wake the server up */
|
||||
BOOL SendData()
|
||||
{
|
||||
CHAR Packet[] = "";
|
||||
INT Ret;
|
||||
|
||||
Ret = sendto(Sock,
|
||||
Packet,
|
||||
sizeof(Packet),
|
||||
0,
|
||||
(SOCKADDR *)&myAddr,
|
||||
sizeof(SOCKADDR_IN));
|
||||
|
||||
if (Ret == SOCKET_ERROR)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL RecieveData(CHAR *Buf)
|
||||
{
|
||||
INT Ret;
|
||||
INT Size = sizeof(SOCKADDR_IN);
|
||||
|
||||
Ret = recvfrom(Sock,
|
||||
Buf,
|
||||
BUFSIZE,
|
||||
0,
|
||||
(SOCKADDR *)&ntpAddr,
|
||||
&Size);
|
||||
if (Ret == SOCKET_ERROR)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
|
@ -20,6 +20,8 @@
|
|||
#define IDC_AUTOSYNC 123
|
||||
#define IDC_SUCSYNC 126
|
||||
#define IDC_NEXTSYNC 127
|
||||
#define IDC_SERVERTEXT 128
|
||||
#define IDC_CLOCK 129
|
||||
|
||||
#define IDS_CPLNAME 1001
|
||||
#define IDS_CPLDESCRIPTION 1002
|
||||
|
|
|
@ -8,15 +8,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
#include <cpl.h>
|
||||
|
||||
#include "resource.h"
|
||||
#include "timedate.h"
|
||||
|
||||
#define SERVERLISTSIZE 6
|
||||
|
||||
typedef struct _TZ_INFO
|
||||
{
|
||||
LONG Bias;
|
||||
|
@ -44,7 +37,7 @@ typedef struct _SERVERS
|
|||
} SERVERS;
|
||||
|
||||
|
||||
#define NUM_APPLETS (1)
|
||||
#define NUM_APPLETS (1)
|
||||
|
||||
LONG APIENTRY
|
||||
Applet(HWND hwnd, UINT uMsg, LONG wParam, LONG lParam);
|
||||
|
@ -100,7 +93,7 @@ SetTimeZoneName(HWND hwnd)
|
|||
|
||||
TimeZoneId = GetTimeZoneInformation(&TimeZoneInfo);
|
||||
|
||||
LoadString(hApplet, IDS_TIMEZONETEXT, TimeZoneText, 128);
|
||||
LoadStringW(hApplet, IDS_TIMEZONETEXT, TimeZoneText, 128);
|
||||
|
||||
switch (TimeZoneId)
|
||||
{
|
||||
|
@ -113,16 +106,16 @@ SetTimeZoneName(HWND hwnd)
|
|||
break;
|
||||
|
||||
case TIME_ZONE_ID_UNKNOWN:
|
||||
LoadString(hApplet, IDS_TIMEZONEUNKNOWN, TimeZoneName, 128);
|
||||
LoadStringW(hApplet, IDS_TIMEZONEUNKNOWN, TimeZoneName, 128);
|
||||
break;
|
||||
|
||||
case TIME_ZONE_ID_INVALID:
|
||||
default:
|
||||
LoadString(hApplet, IDS_TIMEZONEINVALID, TimeZoneName, 128);
|
||||
LoadStringW(hApplet, IDS_TIMEZONEINVALID, TimeZoneName, 128);
|
||||
break;
|
||||
}
|
||||
|
||||
wsprintf(TimeZoneString, TimeZoneText, TimeZoneName);
|
||||
wsprintfW(TimeZoneString, TimeZoneText, TimeZoneName);
|
||||
SendDlgItemMessageW(hwnd, IDC_TIMEZONE, WM_SETTEXT, 0, (LPARAM)TimeZoneString);
|
||||
}
|
||||
|
||||
|
@ -130,12 +123,25 @@ SetTimeZoneName(HWND hwnd)
|
|||
/* Property page dialog callback */
|
||||
INT_PTR CALLBACK
|
||||
DateTimePageProc(HWND hwndDlg,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
InitClockWindowClass();
|
||||
CreateWindowEx(0,
|
||||
L"ClockWndClass",
|
||||
L"Clock",
|
||||
WS_CHILD | WS_VISIBLE,
|
||||
208, 12, 150, 150,
|
||||
hwndDlg,
|
||||
NULL,
|
||||
hApplet,
|
||||
NULL);
|
||||
break;
|
||||
|
||||
case WM_NOTIFY:
|
||||
{
|
||||
LPNMHDR lpnm = (LPNMHDR)lParam;
|
||||
|
@ -179,7 +185,7 @@ GetLargerTimeZoneEntry(DWORD Index)
|
|||
while (Entry != NULL)
|
||||
{
|
||||
if (Entry->Index >= Index)
|
||||
return Entry;
|
||||
return Entry;
|
||||
|
||||
Entry = Entry->Next;
|
||||
}
|
||||
|
@ -203,10 +209,10 @@ CreateTimeZoneList(VOID)
|
|||
PTIMEZONE_ENTRY Current;
|
||||
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
|
||||
0,
|
||||
KEY_ALL_ACCESS,
|
||||
&hZonesKey))
|
||||
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
|
||||
0,
|
||||
KEY_ALL_ACCESS,
|
||||
&hZonesKey))
|
||||
return;
|
||||
|
||||
dwIndex = 0;
|
||||
|
@ -214,131 +220,131 @@ CreateTimeZoneList(VOID)
|
|||
{
|
||||
dwNameSize = 256;
|
||||
lError = RegEnumKeyExW(hZonesKey,
|
||||
dwIndex,
|
||||
szKeyName,
|
||||
&dwNameSize,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
dwIndex,
|
||||
szKeyName,
|
||||
&dwNameSize,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
if (lError != ERROR_SUCCESS && lError != ERROR_MORE_DATA)
|
||||
break;
|
||||
break;
|
||||
|
||||
if (RegOpenKeyExW(hZonesKey,
|
||||
szKeyName,
|
||||
0,
|
||||
KEY_ALL_ACCESS,
|
||||
&hZoneKey))
|
||||
break;
|
||||
szKeyName,
|
||||
0,
|
||||
KEY_ALL_ACCESS,
|
||||
&hZoneKey))
|
||||
break;
|
||||
|
||||
Entry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TIMEZONE_ENTRY));
|
||||
if (Entry == NULL)
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
|
||||
dwValueSize = 64 * sizeof(WCHAR);
|
||||
if (RegQueryValueExW(hZoneKey,
|
||||
L"Display",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->Description,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
L"Display",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->Description,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
|
||||
dwValueSize = 32 * sizeof(WCHAR);
|
||||
if (RegQueryValueExW(hZoneKey,
|
||||
L"Std",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->StandardName,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
L"Std",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->StandardName,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
|
||||
dwValueSize = 32 * sizeof(WCHAR);
|
||||
if (RegQueryValueExW(hZoneKey,
|
||||
L"Dlt",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->DaylightName,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
L"Dlt",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->DaylightName,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
|
||||
dwValueSize = sizeof(DWORD);
|
||||
if (RegQueryValueExW(hZoneKey,
|
||||
L"Index",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->Index,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
L"Index",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->Index,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
|
||||
dwValueSize = sizeof(TZ_INFO);
|
||||
if (RegQueryValueExW(hZoneKey,
|
||||
L"TZI",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->TimezoneInfo,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
L"TZI",
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)&Entry->TimezoneInfo,
|
||||
&dwValueSize))
|
||||
{
|
||||
RegCloseKey(hZoneKey);
|
||||
break;
|
||||
}
|
||||
|
||||
RegCloseKey(hZoneKey);
|
||||
|
||||
if (TimeZoneListHead == NULL &&
|
||||
TimeZoneListTail == NULL)
|
||||
{
|
||||
Entry->Prev = NULL;
|
||||
Entry->Next = NULL;
|
||||
TimeZoneListHead = Entry;
|
||||
TimeZoneListTail = Entry;
|
||||
}
|
||||
TimeZoneListTail == NULL)
|
||||
{
|
||||
Entry->Prev = NULL;
|
||||
Entry->Next = NULL;
|
||||
TimeZoneListHead = Entry;
|
||||
TimeZoneListTail = Entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
Current = GetLargerTimeZoneEntry(Entry->Index);
|
||||
if (Current != NULL)
|
||||
{
|
||||
if (Current == TimeZoneListHead)
|
||||
{
|
||||
/* Prepend to head */
|
||||
Entry->Prev = NULL;
|
||||
Entry->Next = TimeZoneListHead;
|
||||
TimeZoneListHead->Prev = Entry;
|
||||
TimeZoneListHead = Entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Insert before current */
|
||||
Entry->Prev = Current->Prev;
|
||||
Entry->Next = Current;
|
||||
Current->Prev->Next = Entry;
|
||||
Current->Prev = Entry;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Append to tail */
|
||||
Entry->Prev = TimeZoneListTail;
|
||||
Entry->Next = NULL;
|
||||
TimeZoneListTail->Next = Entry;
|
||||
TimeZoneListTail = Entry;
|
||||
}
|
||||
}
|
||||
{
|
||||
Current = GetLargerTimeZoneEntry(Entry->Index);
|
||||
if (Current != NULL)
|
||||
{
|
||||
if (Current == TimeZoneListHead)
|
||||
{
|
||||
/* Prepend to head */
|
||||
Entry->Prev = NULL;
|
||||
Entry->Next = TimeZoneListHead;
|
||||
TimeZoneListHead->Prev = Entry;
|
||||
TimeZoneListHead = Entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Insert before current */
|
||||
Entry->Prev = Current->Prev;
|
||||
Entry->Next = Current;
|
||||
Current->Prev->Next = Entry;
|
||||
Current->Prev = Entry;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Append to tail */
|
||||
Entry->Prev = TimeZoneListTail;
|
||||
Entry->Next = NULL;
|
||||
TimeZoneListTail->Next = Entry;
|
||||
TimeZoneListTail = Entry;
|
||||
}
|
||||
}
|
||||
|
||||
dwIndex++;
|
||||
}
|
||||
|
@ -358,9 +364,9 @@ DestroyTimeZoneList(VOID)
|
|||
|
||||
TimeZoneListHead = Entry->Next;
|
||||
if (TimeZoneListHead != NULL)
|
||||
{
|
||||
TimeZoneListHead->Prev = NULL;
|
||||
}
|
||||
{
|
||||
TimeZoneListHead->Prev = NULL;
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, Entry);
|
||||
}
|
||||
|
@ -385,21 +391,21 @@ ShowTimeZoneList(HWND hwnd)
|
|||
while (Entry != NULL)
|
||||
{
|
||||
SendMessageW(hwnd,
|
||||
CB_ADDSTRING,
|
||||
0,
|
||||
(LPARAM)Entry->Description);
|
||||
CB_ADDSTRING,
|
||||
0,
|
||||
(LPARAM)Entry->Description);
|
||||
|
||||
if (!wcscmp(Entry->StandardName, TimeZoneInfo.StandardName))
|
||||
dwIndex = i;
|
||||
dwIndex = i;
|
||||
|
||||
i++;
|
||||
Entry = Entry->Next;
|
||||
}
|
||||
|
||||
SendMessageW(hwnd,
|
||||
CB_SETCURSEL,
|
||||
(WPARAM)dwIndex,
|
||||
0);
|
||||
CB_SETCURSEL,
|
||||
(WPARAM)dwIndex,
|
||||
0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -412,36 +418,36 @@ SetLocalTimeZone(HWND hwnd)
|
|||
DWORD i;
|
||||
|
||||
dwIndex = SendMessage(hwnd,
|
||||
CB_GETCURSEL,
|
||||
0,
|
||||
0);
|
||||
CB_GETCURSEL,
|
||||
0,
|
||||
0);
|
||||
|
||||
i = 0;
|
||||
Entry = TimeZoneListHead;
|
||||
while (i < dwIndex)
|
||||
{
|
||||
if (Entry == NULL)
|
||||
return;
|
||||
return;
|
||||
|
||||
i++;
|
||||
Entry = Entry->Next;
|
||||
}
|
||||
|
||||
wcscpy(TimeZoneInformation.StandardName,
|
||||
Entry->StandardName);
|
||||
Entry->StandardName);
|
||||
wcscpy(TimeZoneInformation.DaylightName,
|
||||
Entry->DaylightName);
|
||||
Entry->DaylightName);
|
||||
|
||||
TimeZoneInformation.Bias = Entry->TimezoneInfo.Bias;
|
||||
TimeZoneInformation.StandardBias = Entry->TimezoneInfo.StandardBias;
|
||||
TimeZoneInformation.DaylightBias = Entry->TimezoneInfo.DaylightBias;
|
||||
|
||||
memcpy(&TimeZoneInformation.StandardDate,
|
||||
&Entry->TimezoneInfo.StandardDate,
|
||||
sizeof(SYSTEMTIME));
|
||||
&Entry->TimezoneInfo.StandardDate,
|
||||
sizeof(SYSTEMTIME));
|
||||
memcpy(&TimeZoneInformation.DaylightDate,
|
||||
&Entry->TimezoneInfo.DaylightDate,
|
||||
sizeof(SYSTEMTIME));
|
||||
&Entry->TimezoneInfo.DaylightDate,
|
||||
sizeof(SYSTEMTIME));
|
||||
|
||||
/* Set time zone information */
|
||||
SetTimeZoneInformation(&TimeZoneInformation);
|
||||
|
@ -454,18 +460,18 @@ GetAutoDaylightInfo(HWND hwnd)
|
|||
HKEY hKey;
|
||||
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
|
||||
0,
|
||||
KEY_QUERY_VALUE,
|
||||
&hKey))
|
||||
L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
|
||||
0,
|
||||
KEY_QUERY_VALUE,
|
||||
&hKey))
|
||||
return;
|
||||
|
||||
if (RegQueryValueExW(hKey,
|
||||
L"DisableAutoDaylightTimeSet",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL))
|
||||
L"DisableAutoDaylightTimeSet",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL))
|
||||
{
|
||||
SendMessage(hwnd, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
|
||||
}
|
||||
|
@ -485,25 +491,25 @@ SetAutoDaylightInfo(HWND hwnd)
|
|||
DWORD dwValue = 1;
|
||||
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
|
||||
0,
|
||||
KEY_SET_VALUE,
|
||||
&hKey))
|
||||
L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
|
||||
0,
|
||||
KEY_SET_VALUE,
|
||||
&hKey))
|
||||
return;
|
||||
|
||||
if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
|
||||
{
|
||||
RegSetValueExW(hKey,
|
||||
L"DisableAutoDaylightTimeSet",
|
||||
0,
|
||||
REG_DWORD,
|
||||
(LPBYTE)&dwValue,
|
||||
sizeof(DWORD));
|
||||
L"DisableAutoDaylightTimeSet",
|
||||
0,
|
||||
REG_DWORD,
|
||||
(LPBYTE)&dwValue,
|
||||
sizeof(DWORD));
|
||||
}
|
||||
else
|
||||
{
|
||||
RegDeleteValueW(hKey,
|
||||
L"DisableAutoDaylightTimeSet");
|
||||
L"DisableAutoDaylightTimeSet");
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
@ -513,9 +519,9 @@ SetAutoDaylightInfo(HWND hwnd)
|
|||
/* Property page dialog callback */
|
||||
INT_PTR CALLBACK
|
||||
TimeZonePageProc(HWND hwndDlg,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (uMsg)
|
||||
{
|
||||
|
@ -578,13 +584,14 @@ CreateNTPServerList(HWND hwnd)
|
|||
LONG Ret;
|
||||
HKEY hKey;
|
||||
|
||||
hList = GetDlgItem(hwnd, IDC_SERVERLIST);
|
||||
hList = GetDlgItem(hwnd,
|
||||
IDC_SERVERLIST);
|
||||
|
||||
Ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
|
||||
0,
|
||||
KEY_READ,
|
||||
&hKey);
|
||||
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
|
||||
0,
|
||||
KEY_READ,
|
||||
&hKey);
|
||||
if (Ret != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
|
@ -592,14 +599,14 @@ CreateNTPServerList(HWND hwnd)
|
|||
{
|
||||
ValSize = MAX_VALUE_NAME;
|
||||
ValName[0] = '\0';
|
||||
Ret = RegEnumValue(hKey,
|
||||
Index,
|
||||
ValName,
|
||||
&ValSize,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)Data,
|
||||
&dwNameSize);
|
||||
Ret = RegEnumValueW(hKey,
|
||||
Index,
|
||||
ValName,
|
||||
&ValSize,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)Data,
|
||||
&dwNameSize);
|
||||
|
||||
if (Ret == ERROR_SUCCESS)
|
||||
{
|
||||
|
@ -610,7 +617,10 @@ CreateNTPServerList(HWND hwnd)
|
|||
}
|
||||
else
|
||||
{
|
||||
SendMessageW(hList, CB_ADDSTRING, 0, (LPARAM)Data);
|
||||
SendMessageW(hList,
|
||||
CB_ADDSTRING,
|
||||
0,
|
||||
(LPARAM)Data);
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
@ -621,60 +631,131 @@ CreateNTPServerList(HWND hwnd)
|
|||
if (Default < 1 || Default > Index)
|
||||
Default = 1;
|
||||
|
||||
SendMessage(hList, CB_SETCURSEL, --Default, 0);
|
||||
SendMessage(hList,
|
||||
CB_SETCURSEL,
|
||||
--Default,
|
||||
0);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
}
|
||||
|
||||
|
||||
VOID SetNTPServer(HWND hwnd)
|
||||
{
|
||||
HKEY hKey;
|
||||
HWND hList;
|
||||
INT Sel;
|
||||
WCHAR szSel[4];
|
||||
LONG Ret;
|
||||
//DebugBreak();
|
||||
hList = GetDlgItem(hwnd,
|
||||
IDC_SERVERLIST);
|
||||
|
||||
Sel = (INT)SendMessage(hList,
|
||||
CB_GETCURSEL,
|
||||
0,
|
||||
0);
|
||||
|
||||
_itow(Sel, szSel, 10);
|
||||
|
||||
Ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
|
||||
0,
|
||||
KEY_READ,
|
||||
&hKey);
|
||||
if (Ret != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
Ret = RegSetValueExW(hKey,
|
||||
L"",
|
||||
0,
|
||||
REG_SZ,
|
||||
(LPBYTE)szSel,
|
||||
sizeof(szSel));
|
||||
if (Ret == ERROR_SUCCESS)
|
||||
MessageBox(NULL, szSel, NULL, 0);
|
||||
else
|
||||
{
|
||||
WCHAR Buff[20];
|
||||
_itow(Ret, Buff, 10);
|
||||
//MessageBox(NULL, Buff, NULL, 0);
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
VOID UpdateSystemTime(HWND hwndDlg)
|
||||
{
|
||||
//SYSTEMTIME systime;
|
||||
CHAR Buf[BUFSIZE];
|
||||
|
||||
InitialiseConnection();
|
||||
SendData();
|
||||
RecieveData(Buf);
|
||||
DestroyConnection();
|
||||
|
||||
//DateTime_SetSystemtime(hwndDlg, 0, systime);
|
||||
}
|
||||
|
||||
/* Property page dialog callback */
|
||||
INT_PTR CALLBACK
|
||||
InetTimePageProc(HWND hwndDlg,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
|
||||
HWND hCheck;
|
||||
INT Check;
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
CreateNTPServerList(hwndDlg);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
case IDC_UPDATEBUTTON:
|
||||
MessageBox(NULL, L"Boo!", NULL, 0);
|
||||
break;
|
||||
SetNTPServer(hwndDlg);
|
||||
//UpdateSystemTime(hwndDlg);
|
||||
MessageBox(NULL, L"Not yet implemented", NULL, 0);
|
||||
break;
|
||||
|
||||
case IDC_SERVERLIST:
|
||||
if (HIWORD(wParam) == CBN_SELCHANGE)
|
||||
/* Enable the 'Apply' button */
|
||||
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
||||
break;
|
||||
break;
|
||||
|
||||
case IDC_AUTOSYNC:
|
||||
if (HIWORD(wParam) == BN_CLICKED)
|
||||
{
|
||||
hCheck = GetDlgItem(hwndDlg, IDC_AUTOSYNC);
|
||||
Check = (INT)SendMessageW(hCheck, BM_GETCHECK, 0, 0);
|
||||
bSynced = (Check) ? TRUE : FALSE;
|
||||
HWND hCheck = GetDlgItem(hwndDlg, IDC_AUTOSYNC);
|
||||
//HWND hSerText = GetDlgItem(hwndDlg, IDC_SERVERTEXT);
|
||||
//HWND hSerList = GetDlgItem(hwndDlg, IDC_SERVERLIST);
|
||||
//HWND hUpdateBut = GetDlgItem(hwndDlg, IDC_UPDATEBUTTON);
|
||||
//HWND hSucSync = GetDlgItem(hwndDlg, IDC_SUCSYNC);
|
||||
//HWND hNextSync = GetDlgItem(hwndDlg, IDC_NEXTSYNC);
|
||||
|
||||
INT Check = (INT)SendMessageW(hCheck, BM_GETCHECK, 0, 0);
|
||||
if (Check)
|
||||
;//show all data
|
||||
else
|
||||
;//hide all data
|
||||
|
||||
/* Enable the 'Apply' button */
|
||||
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
break;
|
||||
break;
|
||||
|
||||
case WM_NOTIFY:
|
||||
{
|
||||
|
@ -684,11 +765,8 @@ InetTimePageProc(HWND hwndDlg,
|
|||
{
|
||||
case PSN_APPLY:
|
||||
//DebugBreak();
|
||||
SetNTPServer(hwndDlg);
|
||||
|
||||
/* SetNTPServer(GetDlgItem(hwndDlg, IDC_SERVERLIST));
|
||||
SetLocalTimeZone(GetDlgItem(hwndDlg, IDC_TIMEZONELIST));
|
||||
SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
|
||||
*/
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
|
@ -745,9 +823,9 @@ Applet(HWND hwnd, UINT uMsg, LONG wParam, LONG lParam)
|
|||
/* Control Panel Callback */
|
||||
LONG CALLBACK
|
||||
CPlApplet(HWND hwndCpl,
|
||||
UINT uMsg,
|
||||
LPARAM lParam1,
|
||||
LPARAM lParam2)
|
||||
UINT uMsg,
|
||||
LPARAM lParam1,
|
||||
LPARAM lParam2)
|
||||
{
|
||||
int i = (int)lParam1;
|
||||
|
||||
|
@ -781,20 +859,20 @@ CPlApplet(HWND hwndCpl,
|
|||
|
||||
BOOL STDCALL
|
||||
DllMain(HINSTANCE hinstDLL,
|
||||
DWORD dwReason,
|
||||
LPVOID lpReserved)
|
||||
DWORD dwReason,
|
||||
LPVOID lpReserved)
|
||||
{
|
||||
switch (dwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
INITCOMMONCONTROLSEX InitControls;
|
||||
INITCOMMONCONTROLSEX InitControls;
|
||||
|
||||
InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
||||
InitControls.dwICC = ICC_DATE_CLASSES | ICC_PROGRESS_CLASS | ICC_UPDOWN_CLASS;
|
||||
InitCommonControlsEx(&InitControls);
|
||||
InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
||||
InitControls.dwICC = ICC_DATE_CLASSES | ICC_PROGRESS_CLASS | ICC_UPDOWN_CLASS;
|
||||
InitCommonControlsEx(&InitControls);
|
||||
|
||||
hApplet = hinstDLL;
|
||||
hApplet = hinstDLL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
#ifndef __CPL_SAMPLE_H
|
||||
#define __CPL_SAMPLE_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <math.h>
|
||||
#include <commctrl.h>
|
||||
#include <cpl.h>
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#define SERVERLISTSIZE 6
|
||||
#define BUFSIZE 1024
|
||||
#define MYPORT 6
|
||||
#define NTPPORT 6
|
||||
#define ID_TIMER 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int idIcon;
|
||||
|
@ -11,6 +25,18 @@ typedef struct
|
|||
|
||||
extern HINSTANCE hApplet;
|
||||
|
||||
BOOL InitClockWindowClass();
|
||||
|
||||
BOOL InitialiseConnection(VOID);
|
||||
VOID DestroyConnection(VOID);
|
||||
BOOL SendData(VOID);
|
||||
BOOL RecieveData(CHAR *);
|
||||
|
||||
VOID SetIsotropic (HDC hdc, INT cxClient, INT cyClient);
|
||||
VOID RotatePoint (POINT pt[], INT iNum, INT iAngle);
|
||||
VOID DrawClock (HDC hdc);
|
||||
VOID DrawHands (HDC hdc, SYSTEMTIME * pst, BOOL fChange);
|
||||
|
||||
#endif /* __CPL_SAMPLE_H */
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -9,8 +9,12 @@
|
|||
<define name="_WIN32_WINNT">0x501</define>
|
||||
<library>kernel32</library>
|
||||
<library>user32</library>
|
||||
<library>gdi32</library>
|
||||
<library>comctl32</library>
|
||||
<library>ws2_32</library>
|
||||
<library>iphlpapi</library>
|
||||
<file>ntpclient.c</file>
|
||||
<file>clock.c</file>
|
||||
<file>timedate.c</file>
|
||||
<file>timedate.rc</file>
|
||||
</module>
|
||||
|
|
Loading…
Reference in a new issue