日期:2014-05-17  浏览次数:20817 次

windows 程序设计之「NetTime.C」范例分析笔记

windows 程序设计之「NetTime.C」范例分析笔记
2011年01月06日
  /*------------------------------------------------ -------    NETTIME.C -- Sets System Clock from Internet Services                 (c) Charles Petzold, 1998   -------------------------------------------------- -----*/ #include #include"resource.h" #define WM_SOCKET_NOTIFY (WM_USER + 1) #define ID_TIMER         1 LRESULT CALLBACK WndProc   (HWND, UINT, WPARAM, LPARAM) ; BOOL    CALLBACK MainDlg   (HWND, UINT, WPARAM, LPARAM) ; BOOL    CALLBACK ServerDlg (HWND, UINT, WPARAM, LPARAM) ; void ChangeSystemTime (HWND hwndEdit, ULONG ulTime) ; void FormatUpdatedTime (HWND hwndEdit, SYSTEMTIME * pstOld,                                         SYSTEMTIME * pstNew) ; void EditPrintf (HWND hwndEdit, TCHAR * szFormat, ...) ; HINSTANCE hInst ; HWND      hwndModeless ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,                     PSTR szCmdLine, int iCmdShow) {      static TCHAR szAppName[] = TEXT ("NetTime") ;      HWND         hwnd ;      MSG          msg ;      RECT         rect ;      WNDCLASS     wndclass ;      hInst = hInstance ;      wndclass.style         = 0 ;      wndclass.lpfnWndProc   = WndProc ;      wndclass.cbClsExtra    = 0 ;      wndclass.cbWndExtra    = 0 ;      wndclass.hInstance     = hInstance ;      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;      wndclass.hCursor       = NULL ;      wndclass.hbrBackground = NULL ;      wndclass.lpszMenuName  = NULL ;      wndclass.lpszClassName = szAppName ;      if (!RegisterClass (&wndclass))      {           MessageBox (NULL, TEXT ("This program requires Windows NT!"),                        szAppName, MB_ICONERROR) ;           return 0 ;      }      hwnd = CreateWindow (szAppName, TEXT ("Set System Clock from Internet"),                           WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |                                WS_BORDER | WS_MINIMIZEBOX,                           CW_USEDEFAULT, CW_USEDEFAULT,