getdate.c
上传用户:jlteech
上传日期:2007-01-06
资源大小:349k
文件大小:10k
源码类别:

压缩解压

开发平台:

Visual C++

  1. /*
  2.  Copyright (C) 1996 Mike White
  3.  Permission is granted to any individual or institution to use, copy, or
  4.  redistribute this software so long as all of the original files are included,
  5.  that it is not sold for profit, and that this copyright notice is retained.
  6. */
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "wiz.h"
  11. #ifdef __BORLANDC__
  12. #include <dir.h>
  13. #endif
  14. #include <dos.h>
  15. #include "helpids.h"
  16. #include <time.h>
  17. /****************************************************************************
  18.     FUNCTION: GetDateProc(HWND, unsigned, WPARAM, LPARAM)
  19.     PURPOSE:  Processes messages for "Get Files For Archive" dialog box
  20.     MESSAGES:
  21.     WM_INITDIALOG - initialize dialog box
  22.     WM_COMMAND    - Input received
  23. ****************************************************************************/
  24. #ifdef __BORLANDC__
  25. #pragma warn -par
  26. #endif
  27. BOOL WINAPI
  28. GetDateProc(HWND hwndDlg, WORD wMessage, WPARAM wParam, LPARAM lParam)
  29. {
  30. unsigned int i, m, d, y;
  31. struct tm *date;
  32. time_t long_time;
  33. char digits[7];
  34. char Months[13][10] = {"January", "February", "March", "April", "May", "June",
  35.                   "July", "August", "September", "October", "November",
  36.                   "December"};
  37. static HWND hOK;
  38.    switch (wMessage) {
  39.    case WM_INITDIALOG:
  40.       {
  41.       hOK = GetDlgItem(hwndDlg, IDOK);
  42.       for (i = 0; i < 12; i++)
  43.          {
  44.          SendMessage(GetDlgItem(hwndDlg, IDC_MONTH), CB_ADDSTRING,
  45.             0, (LPARAM)(LPCSTR)Months[i]);
  46.          }
  47.       for (i = 1; i < 32; i++)
  48.          {
  49.          SendMessage(GetDlgItem(hwndDlg, IDC_DAY), CB_ADDSTRING,
  50.             0, (LPARAM)(LPCSTR)itoa(i, digits, 10));
  51.          }
  52.       for (i = 1980; i < 2100; i++)
  53.          {
  54.          SendMessage(GetDlgItem(hwndDlg, IDC_YEAR), CB_ADDSTRING,
  55.             0, (LPARAM)(LPCSTR)itoa(i, digits, 10));
  56.          }
  57.       /* Set date to today's date */
  58.       time( &long_time );                 /* Get time as long integer. */
  59.       date = localtime( &long_time );     /* Convert to local time. */
  60.       SendMessage(GetDlgItem(hwndDlg, IDC_MONTH), CB_SELECTSTRING,
  61.          0, (LPARAM)(LPCSTR)Months[date->tm_mon]);
  62.       SendMessage(GetDlgItem(hwndDlg, IDC_DAY), CB_SELECTSTRING,
  63.          0, (LPARAM)(LPCSTR)itoa(date->tm_mday, digits, 10));
  64.       SendMessage(GetDlgItem(hwndDlg, IDC_YEAR), CB_SELECTSTRING,
  65.          0, (LPARAM)(LPCSTR)itoa((date->tm_year+1900), digits, 10));
  66.       CenterDialog(GetParent(hwndDlg), hwndDlg); /* center on parent */
  67.       }
  68.       break;
  69.    case WM_COMMAND:
  70.       switch (LOWORD(wParam)) {
  71.          case IDCANCEL:
  72.             ZpOpt.Date[0] = '';
  73.             EndDialog(hwndDlg, wParam);
  74.             break;
  75.          case IDC_DOWN:
  76.             /* returns are 0 based indexes into list part of combo box */
  77.             m = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_MONTH), CB_GETCURSEL,
  78.                0, 0) + 1;
  79.             d = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_DAY), CB_GETCURSEL,
  80.                0, 0) + 1;
  81.             y = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_YEAR), CB_GETCURSEL,
  82.                0, 0);
  83.             if (d > 1)
  84.                d--;
  85.             else
  86.                {
  87.                if (m > 1)
  88.                   {
  89.                   m--;
  90.                   }
  91.                else
  92.                   {
  93.                   if (y != 0)
  94.                      {
  95.                      y--;
  96.                      m = 12;
  97.                      }
  98.                   }
  99.                switch (m) {
  100.                   case 1:
  101.                      d = 31;
  102.                      break;
  103.                   case 2:
  104.                      d = 29;
  105.                      break;
  106.                   case 3:
  107.                      d = 30;
  108.                      break;
  109.                   case 4:
  110.                      d = 30;
  111.                      break;
  112.                   case 5:
  113.                      d = 31;
  114.                      break;
  115.                   case 6:
  116.                      d = 30;
  117.                      break;
  118.                   case 7:
  119.                      d = 31;
  120.                      break;
  121.                   case 8:
  122.                      d = 31;
  123.                      break;
  124.                   case 9:
  125.                      d = 30;
  126.                      break;
  127.                   case 10:
  128.                      d = 31;
  129.                      break;
  130.                   case 11:
  131.                      d = 30;
  132.                      break;
  133.                   case 12:
  134.                      d = 31;
  135.                      break;
  136.                      }
  137.                }
  138.             SendMessage(GetDlgItem(hwndDlg, IDC_MONTH), CB_SELECTSTRING,
  139.                (unsigned int)-1, (LPARAM)(LPCSTR)Months[m-1]);
  140.             SendMessage(GetDlgItem(hwndDlg, IDC_DAY), CB_SELECTSTRING,
  141.                (unsigned int)-1, (LPARAM)(LPCSTR)itoa(d, digits, 10));
  142.             SendMessage(GetDlgItem(hwndDlg, IDC_YEAR), CB_SELECTSTRING,
  143.                (unsigned int)-1, (LPARAM)(LPCSTR)itoa(y+1980, digits, 10));
  144.             break;
  145.          case IDC_UP:
  146.             /* returns are 0 based indexes into list part of combo box */
  147.             m = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_MONTH), CB_GETCURSEL,
  148.                0, 0) + 1;
  149.             d = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_DAY), CB_GETCURSEL,
  150.                0, 0) + 1;
  151.             y = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_YEAR), CB_GETCURSEL,
  152.                0, 0);
  153.             if (d < 29)
  154.                d++;
  155.             else
  156.                {
  157.                switch (m) {
  158.                   case 1:
  159.                      if (d < 31)
  160.                         d++;
  161.                      else
  162.                         {
  163.                         d = 1;
  164.                         m++;
  165.                         }
  166.                      break;
  167.                   case 2:
  168.                      if (d < 29)
  169.                         d++;
  170.                      else
  171.                         {
  172.                         d = 1;
  173.                         m++;
  174.                         }
  175.                      break;
  176.                   case 3:
  177.                      if (d < 31)
  178.                         d++;
  179.                      else
  180.                         {
  181.                         d = 1;
  182.                         m++;
  183.                         }
  184.                      break;
  185.                   case 4:
  186.                      if (d < 30)
  187.                         d++;
  188.                      else
  189.                         {
  190.                         d = 1;
  191.                         m++;
  192.                         }
  193.                      break;
  194.                   case 5:
  195.                      if (d < 31)
  196.                         d++;
  197.                      else
  198.                         {
  199.                         d = 1;
  200.                         m++;
  201.                         }
  202.                      break;
  203.                   case 6:
  204.                      if (d < 30)
  205.                         d++;
  206.                      else
  207.                         {
  208.                         d = 1;
  209.                         m++;
  210.                         }
  211.                      break;
  212.                   case 7:
  213.                      if (d < 31)
  214.                         d++;
  215.                      else
  216.                         {
  217.                         d = 1;
  218.                         m++;
  219.                         }
  220.                      break;
  221.                   case 8:
  222.                      if (d < 31)
  223.                         d++;
  224.                      else
  225.                         {
  226.                         d = 1;
  227.                         m++;
  228.                         }
  229.                      break;
  230.                   case 9:
  231.                      if (d < 30)
  232.                         d++;
  233.                      else
  234.                         {
  235.                         d = 1;
  236.                         m++;
  237.                         }
  238.                      break;
  239.                   case 10:
  240.                      if (d < 31)
  241.                         d++;
  242.                      else
  243.                         {
  244.                         d = 1;
  245.                         m++;
  246.                         }
  247.                      break;
  248.                   case 11:
  249.                      if (d < 30)
  250.                         d++;
  251.                      else
  252.                         {
  253.                         d = 1;
  254.                         m++;
  255.                         }
  256.                      break;
  257.                   case 12:
  258.                      if (d < 31)
  259.                         d++;
  260.                      else
  261.                         {
  262.                         d = 1;
  263.                         m = 1;
  264.                         y++;
  265.                         }
  266.                      break;
  267.                    }
  268.                }
  269.             SendMessage(GetDlgItem(hwndDlg, IDC_MONTH), CB_SELECTSTRING,
  270.                (unsigned int)-1, (LPARAM)(LPCSTR)Months[m-1]);
  271.             SendMessage(GetDlgItem(hwndDlg, IDC_DAY), CB_SELECTSTRING,
  272.                (unsigned int)-1, (LPARAM)(LPCSTR)itoa(d, digits, 10));
  273.             SendMessage(GetDlgItem(hwndDlg, IDC_YEAR), CB_SELECTSTRING,
  274.                (unsigned int)-1, (LPARAM)(LPCSTR)itoa(y+1980, digits, 10));
  275.             break;
  276.          case IDOK:
  277.             /* returns are 0 based indexes into list part of combo box */
  278.             m = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_MONTH), CB_GETCURSEL,
  279.                0, 0) + 1;
  280.             d = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_DAY), CB_GETCURSEL,
  281.                0, 0) + 1;
  282.             y = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_YEAR), CB_GETCURSEL,
  283.                0, 0);
  284.             y = 80 + y;
  285.             if (y > 99)
  286.                {
  287.                y = y - 100;
  288.                y = y + 2000;
  289.                }
  290.             else
  291.                y = y+1900;
  292.             sprintf(ZpOpt.Date, "%02d%02d%02d", m,d,y);
  293.             EndDialog(hwndDlg, wParam);
  294.             break;
  295.          }
  296.       default:
  297.          break;
  298.    }
  299.    return FALSE;
  300. }
  301. #ifdef __BORLANDC__
  302. #pragma warn .par
  303. #endif