- Add an analog clock to the timedate cpl.
authorGed Murphy <gedmurphy@reactos.org>
Wed, 1 Mar 2006 21:44:17 +0000 (21:44 +0000)
committerGed Murphy <gedmurphy@reactos.org>
Wed, 1 Mar 2006 21:44:17 +0000 (21:44 +0000)
- Add more code towards setting system time via NTP

svn path=/trunk/; revision=21218

reactos/dll/cpl/timedate/En.rc
reactos/dll/cpl/timedate/clock.c [new file with mode: 0644]
reactos/dll/cpl/timedate/ntpclient.c [new file with mode: 0644]
reactos/dll/cpl/timedate/resource.h
reactos/dll/cpl/timedate/timedate.c
reactos/dll/cpl/timedate/timedate.h
reactos/dll/cpl/timedate/timedate.rbuild

index fef082d..a29d2e1 100644 (file)
@@ -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
diff --git a/reactos/dll/cpl/timedate/clock.c b/reactos/dll/cpl/timedate/clock.c
new file mode 100644 (file)
index 0000000..7a21674
--- /dev/null
@@ -0,0 +1,174 @@
+/* Core functions lifted from Programming Windows, Charles Petzold */\r
+\r
+#include "timedate.h"\r
+\r
+#define TWOPI (2 * 3.14159)\r
+\r
+static const TCHAR szClockWndClass[] = TEXT("ClockWndClass");\r
+\r
+\r
+VOID SetIsotropic(HDC hdc, INT cxClient, INT cyClient)\r
+{\r
+     SetMapMode (hdc, MM_ISOTROPIC);\r
+     SetWindowExtEx (hdc, 1000, 1000, NULL);\r
+     SetViewportExtEx (hdc, cxClient / 2, -cyClient / 2, NULL);\r
+     SetViewportOrgEx (hdc, cxClient / 2,  cyClient / 2, NULL);\r
+}\r
+\r
+VOID RotatePoint(POINT pt[], INT iNum, INT iAngle)\r
+{\r
+     INT i;\r
+     POINT ptTemp;\r
+     \r
+     for (i = 0 ; i < iNum ; i++)\r
+     {\r
+          ptTemp.x = (INT) (pt[i].x * cos (TWOPI * iAngle / 360) +\r
+               pt[i].y * sin (TWOPI * iAngle / 360));\r
+          \r
+          ptTemp.y = (INT) (pt[i].y * cos (TWOPI * iAngle / 360) -\r
+               pt[i].x * sin (TWOPI * iAngle / 360));\r
+          \r
+          pt[i] = ptTemp;\r
+     }\r
+}\r
+\r
+VOID DrawClock(HDC hdc)\r
+{\r
+     INT iAngle;\r
+     POINT pt[3];\r
+\r
+     for (iAngle = 0; iAngle < 360; iAngle += 6)\r
+     {\r
+          pt[0].x = 0;\r
+          pt[0].y = 900;\r
+          \r
+          RotatePoint(pt, 1, iAngle);\r
+          \r
+          pt[2].x = pt[2].y = iAngle % 5 ? 33 : 100;\r
+          \r
+          pt[0].x -= pt[2].x / 2;\r
+          pt[0].y -= pt[2].y / 2;\r
+          \r
+          pt[1].x  = pt[0].x + pt[2].x;\r
+          pt[1].y  = pt[0].y + pt[2].y;\r
+          \r
+          SelectObject(hdc, GetStockObject (BLACK_BRUSH));\r
+          \r
+          Ellipse(hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);\r
+     }\r
+}\r
+\r
+VOID DrawHands(HDC hdc, SYSTEMTIME * pst, BOOL fChange)\r
+{\r
+    static POINT pt[3][5] = { {{0, -150}, {100, 0}, {0, 600}, {-100, 0}, {0, -150}},\r
+                              {{0, -200}, { 50, 0}, {0, 800}, { -50, 0}, {0, -200}},\r
+                              {{0,    0}, {  0, 0}, {0,   0}, {   0, 0}, {0,  800}} };\r
+     INT i, iAngle[3];\r
+     POINT ptTemp[3][5];\r
+     \r
+     iAngle[0] = (pst->wHour * 30) % 360 + pst->wMinute / 2;\r
+     iAngle[1] =  pst->wMinute  *  6;\r
+     iAngle[2] =  pst->wSecond  *  6;\r
+     \r
+     memcpy(ptTemp, pt, sizeof(pt));\r
+     \r
+     for (i = fChange ? 0 : 2 ; i < 3 ; i++)\r
+     {\r
+          RotatePoint(ptTemp[i], 5, iAngle[i]);\r
+          \r
+          Polygon(hdc, ptTemp[i], 5);\r
+     }\r
+}\r
+\r
+\r
+static LRESULT CALLBACK\r
+ClockWndProc(HWND hwnd,\r
+             UINT uMsg,\r
+             WPARAM wParam,\r
+             LPARAM lParam)\r
+{\r
+    static INT cxClient, cyClient;\r
+    static SYSTEMTIME stPrevious;\r
+    BOOL fChange;\r
+    HDC hdc;\r
+    PAINTSTRUCT ps;\r
+    SYSTEMTIME st;\r
+\r
+    switch (uMsg)\r
+    {\r
+        case WM_CREATE:\r
+            SetTimer(hwnd, ID_TIMER, 1000, NULL);\r
+            GetLocalTime(&st);\r
+            stPrevious = st;\r
+        break;\r
+\r
+        case WM_SIZE:\r
+            cxClient = LOWORD(lParam);\r
+            cyClient = HIWORD(lParam);\r
+        break;\r
+\r
+        case WM_TIMER:\r
+            GetLocalTime(&st);\r
+\r
+            fChange = st.wHour   != stPrevious.wHour ||\r
+                    st.wMinute != stPrevious.wMinute;\r
+\r
+            hdc = GetDC(hwnd);\r
+\r
+            SetIsotropic(hdc, cxClient, cyClient);\r
+\r
+            InvalidateRect(hwnd, NULL, TRUE);\r
+\r
+            SelectObject(hdc, GetStockObject(BLACK_PEN));\r
+            DrawHands(hdc, &st, TRUE);\r
+\r
+            ReleaseDC(hwnd, hdc);\r
+\r
+            stPrevious = st;\r
+        break;\r
+\r
+        case WM_PAINT:\r
+            hdc = BeginPaint(hwnd, &ps);\r
+\r
+            SetIsotropic(hdc, cxClient, cyClient);\r
+\r
+            DrawClock(hdc);\r
+            SelectObject(hdc, GetStockObject(WHITE_BRUSH));\r
+            DrawHands(hdc, &stPrevious, TRUE);\r
+\r
+            EndPaint(hwnd, &ps);\r
+        break;\r
+\r
+        case WM_DESTROY:\r
+            KillTimer(hwnd, ID_TIMER);\r
+        break;\r
+\r
+        default:\r
+            DefWindowProc(hwnd, \r
+                          uMsg, \r
+                          wParam, \r
+                          lParam);\r
+    }\r
+\r
+    return TRUE;\r
+}\r
+\r
+\r
+\r
+BOOL\r
+InitClockWindowClass(VOID)\r
+{\r
+    WNDCLASSEX wc = {0};\r
+\r
+    wc.cbSize = sizeof(WNDCLASSEX);\r
+    wc.style = CS_HREDRAW | CS_VREDRAW;\r
+    wc.lpfnWndProc = ClockWndProc;\r
+    wc.hInstance = hApplet;\r
+    wc.hIcon = NULL;\r
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);\r
+    wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);\r
+    wc.lpszClassName = szClockWndClass;\r
+    wc.hIconSm = NULL;\r
+\r
+    return RegisterClassEx(&wc) != (ATOM)0;\r
+}\r
diff --git a/reactos/dll/cpl/timedate/ntpclient.c b/reactos/dll/cpl/timedate/ntpclient.c
new file mode 100644 (file)
index 0000000..e2c7aa0
--- /dev/null
@@ -0,0 +1,87 @@
+#include "timedate.h"\r
+\r
+SOCKET Sock;\r
+SOCKADDR_IN myAddr, ntpAddr;\r
+\r
+BOOL InitialiseConnection()\r
+{\r
+    WSADATA wsaData;\r
+    INT Ret;\r
+\r
+    Ret = WSAStartup(MAKEWORD(2, 2),\r
+                     &wsaData);\r
+    if (Ret != 0)\r
+        return FALSE;\r
+\r
+\r
+    Sock = WSASocket(AF_INET,\r
+                     SOCK_DGRAM,\r
+                     IPPROTO_UDP,\r
+                     NULL,\r
+                     0,\r
+                     WSA_FLAG_OVERLAPPED);\r
+    if (Sock == INVALID_SOCKET )\r
+        return FALSE;\r
+\r
+    /* setup client socket */\r
+    ZeroMemory(&myAddr, sizeof(myAddr));\r
+    myAddr.sin_family = AF_INET;\r
+    myAddr.sin_port = htons(IPPORT_TIMESERVER);\r
+    myAddr.sin_addr.s_addr = INADDR_ANY;\r
+\r
+    Ret = bind(Sock,\r
+               (SOCKADDR *)&myAddr,\r
+               sizeof(SOCKADDR));\r
+    if (Ret == SOCKET_ERROR)\r
+        return FALSE;\r
+\r
+    /* setup server socket */\r
+    ZeroMemory(&ntpAddr, sizeof(ntpAddr));\r
+    ntpAddr.sin_family = AF_INET;\r
+    ntpAddr.sin_port = htons(IPPORT_TIMESERVER);\r
+    ntpAddr.sin_addr.s_addr = INADDR_ANY;\r
+\r
+    return TRUE;\r
+}\r
+\r
+VOID DestroyConnection()\r
+{\r
+    WSACleanup();\r
+}\r
+\r
+/* send some data to wake the server up */\r
+BOOL SendData()\r
+{\r
+    CHAR Packet[] = "";\r
+    INT Ret;\r
+\r
+    Ret = sendto(Sock,\r
+                 Packet,\r
+                 sizeof(Packet),\r
+                 0,\r
+                 (SOCKADDR *)&myAddr,\r
+                 sizeof(SOCKADDR_IN));\r
+\r
+    if (Ret == SOCKET_ERROR)\r
+        return FALSE;\r
+\r
+    return TRUE;\r
+}\r
+\r
+\r
+BOOL RecieveData(CHAR *Buf)\r
+{\r
+    INT Ret;\r
+    INT Size = sizeof(SOCKADDR_IN);\r
+\r
+    Ret = recvfrom(Sock,\r
+                   Buf,\r
+                   BUFSIZE,\r
+                   0,\r
+                   (SOCKADDR *)&ntpAddr,\r
+                   &Size);\r
+    if (Ret == SOCKET_ERROR)\r
+        return FALSE;\r
+\r
+    return TRUE;\r
+}\r
index d9f0b33..31303eb 100644 (file)
@@ -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
index e744910..bbf74b8 100644 (file)
@@ -5,18 +5,11 @@
  * PURPOSE:     ReactOS Timedate Control Panel
  * COPYRIGHT:   Copyright 2004-2005 Eric Kohl
  *              Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
- *               
+ *
  */
 
-#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);
@@ -58,7 +51,7 @@ PTIMEZONE_ENTRY TimeZoneListTail = NULL;
 
 
 /* Applets */
-APPLET Applets[NUM_APPLETS] = 
+APPLET Applets[NUM_APPLETS] =
 {
   {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, Applet}
 };
@@ -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,30 +584,31 @@ 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;
 
-    while (TRUE) 
+    while (TRUE)
     {
-            ValSize = MAX_VALUE_NAME; 
-            ValName[0] = '\0'; 
-            Ret = RegEnumValue(hKey, 
-                               Index, 
-                               ValName, 
-                               &ValSize, 
-                               NULL, 
-                               NULL,
-                               (LPBYTE)Data,
-                               &dwNameSize);
-            if (Ret == ERROR_SUCCESS) 
+            ValSize = MAX_VALUE_NAME;
+            ValName[0] = '\0';
+            Ret = RegEnumValueW(hKey,
+                                Index,
+                                ValName,
+                                &ValSize,
+                                NULL,
+                                NULL,
+                                (LPBYTE)Data,
+                                &dwNameSize);
+
+            if (Ret == ERROR_SUCCESS)
             {
                 if (wcscmp(ValName, L"") == 0)
                 {
@@ -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(GetDlgItem(hwndDlg, IDC_SERVERLIST));
-                    SetLocalTimeZone(GetDlgItem(hwndDlg, IDC_TIMEZONELIST));
-                    SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
-                */
+                    SetNTPServer(hwndDlg);
+
                     return TRUE;
 
                 default:
@@ -745,12 +823,12 @@ 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;
-  
+
   switch (uMsg)
   {
     case CPL_INIT:
@@ -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;
   }
index 817bd4f..c6d82d5 100644 (file)
@@ -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 */
index 43e087b..a595359 100644 (file)
@@ -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>