home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / WINDATE.ZIP / DATEST.C < prev    next >
C/C++ Source or Header  |  1991-02-27  |  25KB  |  667 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: Datest.c
  4.          by Mark Jones, (214) 291-0509
  5.              Compuserve 70511,706
  6.  
  7.     PURPOSE: Tests the DATE.DLL routines
  8.  
  9.     FUNCTIONS:
  10.  
  11.     WinMain() - calls initialization function, processes message loop
  12.     InitApplication() - initializes window data and registers window
  13.     InitInstance() - saves instance handle and creates main window
  14.     MainWndProc() - processes messages
  15.     About() - processes messages for "About" dialog box
  16.  
  17. ****************************************************************************/
  18. /*****************************************************************************
  19.  
  20.                            MODIFICATION LOG
  21.  
  22. Date     Version  Who      Change
  23. ----     -------  ---      --------------------------------------------------
  24. 3 OCT 90 1.00     Mark J.  Originated
  25. 22 OCT   1.01     Mark J.  Add _WINDOWS and recompiled with warning level 3
  26.                            (W3), fixing certain conversion warnings
  27. 2/10/91                    Changed "<win.h>" reference to <windows.h>
  28.  
  29.  
  30. *****************************************************************************/
  31.  
  32. #define _WINDOWS
  33.  
  34. #include <windows.h>                // needed for all windows app's
  35. #include <stdlib.h>                 /* needed for strtol() */
  36. #include "Datest.h"                 /* specific to this program */
  37. #include "Date.h"
  38.  
  39. HANDLE hInst;                       /* current instance */
  40. HWND hParent;                       /* main parent window */
  41. HWND hTestDialog;                   /* handle of DateTest dialog box */
  42. HWND hDateObjDialog;                /* handle of DateObjDlg dialog box */
  43. HWND hDateObjLB;                    /* handle to DateObjDlg list box */
  44. HANDLE hDateObj;                    /* handle to DateObj */
  45.  
  46. /****************************************************************************
  47.  
  48.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  49.  
  50.     PURPOSE: calls initialization function, processes message loop
  51.  
  52. ****************************************************************************/
  53.  
  54. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  55. HANDLE hInstance;                            /* current instance             */
  56. HANDLE hPrevInstance;                        /* previous instance            */
  57. LPSTR lpCmdLine;                             /* command line                 */
  58. int nCmdShow;                                /* show-window type (open/icon) */
  59. {
  60.     MSG msg;                                 /* message                      */
  61.  
  62.    if (!hPrevInstance)                  /* Other instances of app running? */
  63.     if (!InitApplication(hInstance)) /* Initialize shared things */
  64.         return (FALSE);              /* Exits if unable to initialize     */
  65.  
  66.     /* Perform initializations that apply to a specific instance */
  67.  
  68.     if (!InitInstance(hInstance, nCmdShow))
  69.       return (FALSE);
  70.  
  71.     /* Acquire and dispatch messages until a WM_QUIT message is received. */
  72.  
  73.     while (GetMessage(&msg,        /* message structure                      */
  74.              NULL,                  /* handle of window receiving the message */
  75.              NULL,                  /* lowest message to examine              */
  76.              NULL))                 /* highest message to examine             */
  77.       {
  78.       if (!IsDialogMessage(hDateObjDialog, &msg) &&
  79.           !IsDialogMessage(hTestDialog, &msg)
  80.          )
  81.           {
  82.           TranslateMessage(&msg);        /* Translates virtual key codes   */
  83.           DispatchMessage(&msg);         /* Dispatches message to window   */
  84.           }
  85.       }
  86.     return (msg.wParam);           /* Returns the value from PostQuitMessage */
  87. }
  88.  
  89.  
  90. /****************************************************************************
  91.  
  92.     FUNCTION: InitApplication(HANDLE)
  93.  
  94.     PURPOSE: Initializes window data and registers window class
  95.  
  96.     COMMENTS:
  97.  
  98.     This function is called at initialization time only if no other 
  99.     instances of the application are running.  This function performs 
  100.     initialization tasks that can be done once for any number of running 
  101.     instances.  
  102.  
  103.     In this case, we initialize a window class by filling out a data 
  104.     structure of type WNDCLASS and calling the Windows RegisterClass() 
  105.     function.  Since all instances of this application use the same window 
  106.     class, we only need to do this when the first instance is initialized.  
  107.  
  108.  
  109. ****************************************************************************/
  110.  
  111. BOOL InitApplication(hInstance)
  112. HANDLE hInstance;                              /* current instance           */
  113. {
  114.     WNDCLASS  wc;
  115.  
  116.     /* Fill in window class structure with parameters that describe the       */
  117.     /* main window.                                                           */
  118.  
  119.     wc.style = NULL;                    /* Class style(s).                    */
  120.     wc.lpfnWndProc = MainWndProc;       /* Function to retrieve messages for  */
  121.                                         /* windows of this class.             */
  122.     wc.cbClsExtra = 0;                  /* No per-class extra data.           */
  123.     wc.cbWndExtra = 0;                  /* No per-window extra data.          */
  124.     wc.hInstance = hInstance;           /* Application that owns the class.   */
  125.     wc.hIcon = LoadIcon(hInstance, "DatestIcon");
  126.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  127.     wc.hbrBackground = COLOR_BACKGROUND;
  128.     wc.lpszMenuName =  "DatestMenu";   /* Name of menu resource in .RC file. */
  129.     wc.lpszClassName = "DatestWClass"; /* Name used in call to CreateWindow. */
  130.  
  131.     /* Register the window class and return success/failure code. */
  132.  
  133.     return (RegisterClass(&wc));
  134.  
  135. }
  136.  
  137.  
  138. /****************************************************************************
  139.  
  140.     FUNCTION:  InitInstance(HANDLE, int)
  141.  
  142.     PURPOSE:  Saves instance handle and creates main window
  143.  
  144.     COMMENTS:
  145.  
  146.     This function is called at initialization time for every instance of 
  147.     this application.  This function performs initialization tasks that 
  148.     cannot be shared by multiple instances.  
  149.  
  150.     In this case, we save the instance handle in a static variable and 
  151.     create and display the main program window.  
  152.     
  153. ****************************************************************************/
  154.  
  155. BOOL InitInstance(hInstance, nCmdShow)
  156.    HANDLE          hInstance;          /* Current instance identifier.       */
  157.    int             nCmdShow;           /* Param for first ShowWindow() call. */
  158. {
  159.    HWND            hWnd;               /* Main window handle.                */
  160.    long lResult;                       /* LONG return value */
  161.  
  162.    /* Save the instance handle in static variable, which will be used in  */
  163.    /* many subsequence calls from this application to Windows.            */
  164.  
  165.    hInst = hInstance;
  166.    hParent = 0;
  167.  
  168.    /* Create a main window for this application instance.  */
  169.  
  170.    hWnd = CreateWindow(
  171.       "DatestWClass",                /* See RegisterClass() call.          */
  172.       "Datest - Test DATE.DLL functions", /* Text for window title bar.            */
  173.       WS_OVERLAPPEDWINDOW,            /* Window style.                      */
  174.       CW_USEDEFAULT,                  /* Default horizontal position.       */
  175.       CW_USEDEFAULT,                  /* Default vertical position.         */
  176.       CW_USEDEFAULT,                  /* Default width.                     */
  177.       CW_USEDEFAULT,                  /* Default height.                    */
  178.       NULL,                           /* Overlapped windows have no parent. */
  179.       NULL,                           /* Use the window class menu.         */
  180.       hInstance,                      /* This instance owns this window.    */
  181.       NULL                            /* Pointer not needed.                */
  182.    );
  183.  
  184.    /* If window could not be created, return "failure" */
  185.    if (!hWnd)
  186.      return (FALSE);
  187.    hParent = hWnd;
  188.  
  189.    // Create my modeless DateTest dialog box
  190.    hTestDialog = CreateDialog(hInst, "DATETEST", hParent,
  191.           MakeProcInstance(DateTest, hInst));
  192.    if (!hTestDialog)
  193.      {
  194.      MessageBox(hParent, "Cannot create Date-test dialog box",
  195.              "FATAL ERROR", MB_ICONSTOP | MB_OK);
  196.      return (FALSE);
  197.      }
  198.  
  199.    // Create my modeless DateObjDlg dialog box
  200.    hDateObjDialog = CreateDialog(hInst, "DATEOBJ", hParent,
  201.           MakeProcInstance(DateObjDlg, hInst));
  202.    if (!hDateObjDialog)
  203.       {
  204.       MessageBox(hParent, "Cannot create DateObjDlg dialog box",
  205.                 "FATAL ERROR", MB_ICONSTOP | MB_OK);
  206.       return (FALSE);
  207.       }
  208.    else
  209.       {
  210.                                           // Set up Normal as calculation mode
  211.       CheckDlgButton(hDateObjDialog, IDD_NORMALMODE, 1);
  212.       hDateObj = NULL;                    // Allocate a DateObj instance
  213.       lResult = DateObj(0, CREATE, DATE, 0);
  214.       if (HIWORD(lResult) == DATE_ERROR)
  215.          {
  216.          MessageBox(hParent, "Cannot create DateObj instance",
  217.                    "FATAL ERROR", MB_ICONSTOP | MB_OK);
  218.          return (FALSE);
  219.          }
  220.       else
  221.          hDateObj = LOWORD(lResult);      // Store handle to DateObj instance
  222.                                           // Store handle to list box
  223.          hDateObjLB = GetDlgItem(hDateObjDialog, IDD_DATEOBJCONTENTS);
  224.       }
  225.  
  226.    /* Make the window visible; update its client area; and return "success" */
  227.    ShowWindow(hWnd, nCmdShow); /* Show the window                         */
  228.    UpdateWindow(hWnd);         /* Sends WM_PAINT message                  */
  229.    SetFocus(hWnd);             /* Moves focus to the main window */
  230.  
  231.    return (TRUE);              /* Returns the value from PostQuitMessage */
  232. }
  233.  
  234. /****************************************************************************
  235.  
  236.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  237.  
  238.     PURPOSE:  Processes messages
  239.  
  240.     MESSAGES:
  241.  
  242.     WM_COMMAND    - application menu (About dialog box)
  243.     WM_DESTROY    - destroy window
  244.  
  245.     COMMENTS:
  246.  
  247.     To process the IDM_ABOUT message, call MakeProcInstance() to get the
  248.     current instance address of the About() function.  Then call Dialog
  249.     box which will create the box according to the information in your
  250.     Datest.rc file and turn control over to the About() function.   When
  251.     it returns, free the intance address.
  252.  
  253. ****************************************************************************/
  254.  
  255. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  256. HWND hWnd;                                /* window handle                   */
  257. unsigned message;                         /* type of message                 */
  258. WORD wParam;                              /* additional information          */
  259. LONG lParam;                              /* additional information          */
  260. {
  261.    FARPROC lpProcAbout;                   /* pointer to the "About" function */
  262.    LONG lResult;
  263.  
  264.     switch (message)
  265.       {
  266.        case WM_COMMAND:           /* message: command from application menu */
  267.  
  268.           switch (wParam)
  269.              {
  270.              case IDM_ABOUT:
  271.                     lpProcAbout = MakeProcInstance(About, hInst);
  272.  
  273.                     DialogBox(hInst,             /* current instance         */
  274.                     "AboutBox",                 /* resource to use          */
  275.                     hWnd,                       /* parent handle            */
  276.                     lpProcAbout);               /* About() instance address */
  277.  
  278.                     FreeProcInstance(lpProcAbout);
  279.                     break;
  280.  
  281.              case IDM_TEST:
  282.                     TestDateRoutines(hWnd);    /* test primitive DATE.DLL */
  283.                     break;
  284.  
  285.              case IDM_OOP:
  286.                     TestDateObj(hWnd);         /* test OOP DATE.DLL */
  287.                     break;
  288.  
  289.              case IDM_EXIT:
  290.                     DestroyWindow(hWnd);       /* close main window */
  291.                     break;
  292.  
  293.              }
  294.              return (DefWindowProc(hWnd, message, wParam, lParam));
  295.  
  296.          case WM_DESTROY:                  /* message: window being destroyed */
  297.                 KillTimer(hTestDialog, TIMER_DATETEST); /* Stop the timer */
  298.                if (hDateObj)
  299.                   {
  300.                   lResult = DateObj(hDateObj, DELETE, DATE, 0);
  301.                   if (HIWORD(lResult) == DATE_ERROR)
  302.                      MessageBox(hParent, "Cannot delete DateObj instance",
  303.                                "FATAL ERROR", MB_ICONSTOP | MB_OK);
  304.                   hDateObj = 0;
  305.                   }
  306.                 PostQuitMessage(0);
  307.                 break;
  308.  
  309.          default:                          /* Passes it on if unproccessed    */
  310.                 return (DefWindowProc(hWnd, message, wParam, lParam));
  311.       }
  312.     return (NULL);
  313. }
  314.  
  315.  
  316. /****************************************************************************
  317.  
  318.     FUNCTION: About(HWND, unsigned, WORD, LONG)
  319.  
  320.     PURPOSE:  Processes messages for "About" dialog box
  321.  
  322.     MESSAGES:
  323.  
  324.     WM_INITDIALOG - initialize dialog box
  325.     WM_COMMAND    - Input received
  326.  
  327.     COMMENTS:
  328.  
  329.     No initialization is needed for this particular dialog box, but TRUE
  330.     must be returned to Windows.
  331.  
  332.     Wait for user to click on "Ok" button, then close the dialog box.
  333.  
  334. ****************************************************************************/
  335.  
  336. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  337. HWND hDlg;                                /* window handle of the dialog box */
  338. unsigned message;                         /* type of message                 */
  339. WORD wParam;                              /* message-specific information    */
  340. LONG lParam;
  341. {
  342.     switch (message) {
  343.     case WM_INITDIALOG:                /* message: initialize dialog box */
  344.         return (TRUE);
  345.  
  346.     case WM_COMMAND:                      /* message: received a command */
  347.         if (wParam == IDOK                /* "OK" box selected?          */
  348.         || wParam == IDCANCEL) {      /* System menu close command? */
  349.         EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
  350.         return (TRUE);
  351.         }
  352.         break;
  353.     }
  354.     return (FALSE);                           /* Didn't process a message    */
  355. }
  356.  
  357.  
  358. /****************************************************************************
  359.  
  360.     FUNCTION: VOID TestDateRoutines(VOID)
  361.  
  362.     PURPOSE:  Calls the DATE.DLL primitive functions to test their accuracy
  363.  
  364.     COMMENTS:
  365.  
  366. ****************************************************************************/
  367.  
  368. VOID TestDateRoutines(HWND hWnd)
  369. {
  370.     #define FREQ_MILLISECONDS 250
  371.  
  372.     while (!SetTimer(hTestDialog, TIMER_DATETEST, FREQ_MILLISECONDS, NULL))
  373.     {
  374.     if (IDCANCEL == MessageBox(hParent,
  375.         "Too many clocks or timers!  Close other windows and retry.",
  376.         "RESOURCES UNAVAILABLE",MB_ICONEXCLAMATION | MB_RETRYCANCEL) )
  377.         return;
  378.     }
  379.     SendMessage(hTestDialog, WM_INITDIALOG, NULL, NULL);
  380.     ShowWindow(hTestDialog, SW_SHOWNORMAL);
  381. }
  382.  
  383.  
  384. /****************************************************************************
  385.  
  386.     FUNCTION: DateTest(HWND, unsigned, WORD, LONG)
  387.  
  388.     PURPOSE:  Processes messages for "DateTest" dialog box
  389.  
  390.     MESSAGES:
  391.  
  392.     WM_INITDIALOG - initialize dialog box
  393.     WM_COMMAND    - Input received
  394.  
  395.     COMMENTS:
  396.  
  397.  
  398. ****************************************************************************/
  399.  
  400. BOOL FAR PASCAL DateTest(hDlg, message, wParam, lParam)
  401. HWND hDlg;                                /* window handle of the dialog box */
  402. unsigned message;                         /* type of message                 */
  403. WORD wParam;                              /* message-specific information    */
  404. LONG lParam;
  405. {
  406.     static long lJulianDate = 0;            /* persistent julian date */
  407.     static Date DateStruct = {0};           /* Date structure */
  408.     static Date *DStruct = &DateStruct;     /* ptr to Date structure */
  409.     #define MAXSTRSIZE 20                   /* Maximum size of string buffer */
  410.     unsigned char szBuffer[MAXSTRSIZE];     /* string to hold stuff */
  411.     long lWorkFld;                          /* general-purpose field */
  412.  
  413.     int nLoopCtr;                           /* temporary loop counter */
  414.     #define ITERATIONS 6                    /* number of calc's per WM_TIMER */
  415.  
  416.     switch (message) {
  417.  
  418.     case WM_INITDIALOG:                /* message: initialize dialog box */
  419.         lJulianDate = 1;
  420.         return (TRUE);
  421.  
  422.     case WM_COMMAND:                      /* message: received a command */
  423.         if (wParam == IDD_DATETESTCANCEL  /* "CANCEL" box selected?      */
  424.         || wParam == IDCANCEL)        /* System menu close command? */
  425.         {
  426.         KillTimer(hDlg, TIMER_DATETEST); /* Stop the timer */
  427.         ShowWindow(hTestDialog, SW_HIDE); /* hide the dialog box */
  428.         return (TRUE);                /* return */
  429.         }
  430.         break;
  431.  
  432.     case WM_TIMER:                      /* do some more iterations */
  433.         for (nLoopCtr=0; nLoopCtr < ITERATIONS; lJulianDate++, nLoopCtr++)
  434.         {
  435.         if (lJulianDate > MAX_JULIAN)
  436.             lJulianDate = 1;
  437.  
  438.         // Set up julian date
  439.         DStruct->lJulianDate = lJulianDate;
  440.  
  441.         // Display julian date
  442.         wsprintf(szBuffer, "%lu", lJulianDate);/* put val in string */
  443.                                              /* change dlg text */
  444.         SetDlgItemText(hDlg, IDD_DATETESTINT, (LPSTR) szBuffer);
  445.  
  446.         // Call DATE.DLL
  447.         CalcNormalDate((Date far *) DStruct);   /* get normal date */
  448.         if (DStruct->nError)                    /* if bug, */
  449.             {                                   /* prompt & exit */
  450.             KillTimer(hDlg, TIMER_DATETEST); /* Stop the timer */
  451.             MessageBox(hParent, "DATE.DLL error!", "FATAL ERROR",
  452.             MB_ICONEXCLAMATION | MB_OK);
  453.             ShowWindow(hTestDialog, SW_HIDE); /* hide the dialog box */
  454.             break;
  455.             }
  456.  
  457.         // Display normal results
  458.         // PERCENT DONE WITH TEST:
  459.         lWorkFld = (lJulianDate * 100) / MAX_JULIAN;
  460.         wsprintf(szBuffer, "%3lu%%", lWorkFld ? lWorkFld : 1);
  461.         SetDlgItemText(hDlg, IDD_PCNTDONE, (LPSTR) szBuffer);
  462.         // DATE:
  463.         wsprintf(szBuffer, "%2d/%2d/%4d", DStruct->nMonth,
  464.                 DStruct->nDay, DStruct->nYear);
  465.         SetDlgItemText(hDlg, IDD_MMDDYYYY, (LPSTR) szBuffer);
  466.         // DAY OF WEEK:
  467.         wsprintf(szBuffer, "%1d", DStruct->nDayOfWeek);
  468.         SetDlgItemText(hDlg, IDD_DOWVAL, (LPSTR) szBuffer);
  469.         // DAY # IN YEAR:
  470.         wsprintf(szBuffer, "%3d", DStruct->nYearDays);
  471.         SetDlgItemText(hDlg, IDD_YEARDAYVAL, (LPSTR) szBuffer);
  472.         // LEAP YEAR?
  473.         wsprintf(szBuffer, "%s", DStruct->nLeapYear ?
  474.                   (LPSTR) "Yes" : (LPSTR) "No");
  475.         SetDlgItemText(hDlg, IDD_LEAPVAL, (LPSTR) szBuffer);
  476.  
  477.         }
  478.         break;
  479.  
  480.     }
  481.     return (FALSE);                           /* Didn't process a message    */
  482. }
  483.  
  484.  
  485. /****************************************************************************
  486.  
  487.     FUNCTION: VOID TestDateObj(VOID)
  488.  
  489.     PURPOSE:  Calls the DateObj() function to test its accuracy
  490.  
  491.     COMMENTS:
  492.  
  493. ****************************************************************************/
  494.  
  495. VOID TestDateObj(HWND hWnd)
  496. {
  497.    SendMessage(hDateObjDialog, WM_INITDIALOG, NULL, NULL);
  498.    ShowWindow(hDateObjDialog, SW_SHOWNORMAL);
  499.    if (!UpdateDateObjLB(hDateObjLB, hDateObj))
  500.       MessageBox(hParent, "Cannot initialize DateObj list box",
  501.                 "FATAL ERROR", MB_ICONSTOP | MB_OK);
  502. }
  503.  
  504.  
  505. /****************************************************************************
  506.  
  507.     FUNCTION: DateObjDlg(HWND, unsigned, WORD, LONG)
  508.  
  509.     PURPOSE:  Processes messages for "DateObj" dialog box
  510.  
  511.     MESSAGES:
  512.  
  513.     WM_INITDIALOG - initialize dialog box
  514.     WM_COMMAND    - Input received
  515.  
  516.     COMMENTS:
  517.  
  518.  
  519. ****************************************************************************/
  520.  
  521. BOOL FAR PASCAL DateObjDlg(hDlg, message, wParam, lParam)
  522. HWND hDlg;                                /* window handle of the dialog box */
  523. unsigned message;                         /* type of message                 */
  524. WORD wParam;                              /* message-specific information    */
  525. LONG lParam;
  526. {
  527.    WORD nMonth = 0;                       /* Normal-date fields */
  528.    WORD nDay = 0;
  529.    WORD nYear = 0;
  530.    LONG lJulianDate = 0;                  /* Julian-date field */
  531.    #define MAXJULEN 20
  532.    BYTE szJulianDate[MAXJULEN+1];         /* Julian-date string */
  533.    WORD nFromNormal = 1;                  /* Calc from Normal date ? */
  534.    LONG lResult;                          /* DateObj() result field */
  535.  
  536.    switch (message)
  537.      {
  538.      case WM_INITDIALOG:                  /* message: initialize dialog box */
  539.          return (TRUE);
  540.  
  541.      case WM_COMMAND:                     /* message: received a command */
  542.         switch (wParam)
  543.            {
  544.            case IDD_CANCEL:
  545.            case IDCANCEL:                 /* hide the dialog box */
  546.                ShowWindow(hDateObjDialog, SW_HIDE);
  547.                return (TRUE);
  548.  
  549.            case IDD_UPDATE:               /* put fields into DateObj instance */
  550.                nMonth = GetDlgItemInt(hDateObjDialog, IDD_MONTH, 0, 0);
  551.                nDay = GetDlgItemInt(hDateObjDialog, IDD_DAY, 0, 0);
  552.                nYear = GetDlgItemInt(hDateObjDialog, IDD_YEAR, 0, 0);
  553.                GetDlgItemText(hDateObjDialog, IDD_JULIAN, (LPSTR) szJulianDate,
  554.                               MAXJULEN);
  555.                lJulianDate = strtol(szJulianDate, 0, 0);
  556.                lResult = DateObj(hDateObj, SET, MONTH, (LONG) nMonth);
  557.                lResult = DateObj(hDateObj, SET, DAY, (LONG) nDay);
  558.                lResult = DateObj(hDateObj, SET, YEAR, (LONG) nYear);
  559.                lResult = DateObj(hDateObj, SET, JULIANDATE, lJulianDate);
  560.                UpdateDateObjLB(hDateObjLB, hDateObj);
  561.                break;
  562.  
  563.             case IDD_CALCULATE:
  564.                nFromNormal = IsDlgButtonChecked(hDateObjDialog,
  565.                                                 IDD_NORMALMODE);
  566.                if (nFromNormal)
  567.                   lResult = DateObj(hDateObj, CALCULATE, 0, NORMAL);
  568.                else
  569.                   lResult = DateObj(hDateObj, CALCULATE, 0, JULIAN);
  570.                UpdateDateObjLB(hDateObjLB, hDateObj);
  571.                break;
  572.             }
  573.         break;
  574.      }
  575.    return (FALSE);                           /* Didn't process a message    */
  576. }
  577.  
  578.  
  579. /****************************************************************************
  580.  
  581.     FUNCTION: UpdateDateObjLB(HWND hLB, HANDLE hDateObj)
  582.  
  583.     PURPOSE:  Updates contents of hLB list box with hDateObj instance data
  584.  
  585.     COMMENTS:
  586.  
  587.  
  588. ****************************************************************************/
  589.  
  590. BOOL UpdateDateObjLB(HWND hLB, HANDLE hDateObj)
  591. {
  592.    #define MAXLEN 20
  593.    LONG lResult = 0;
  594.    BOOL bResult = 1;
  595.    BYTE szString[MAXLEN+1];
  596.  
  597.    if (!hLB || !hDateObj)                    // If any NULL handles,
  598.       return (0);                            //  abort w/failure
  599.    SendMessage(hLB, LB_RESETCONTENT, 0, 0);  // Tell list box to clear itself
  600.    SendMessage(hLB, WM_SETREDRAW, 0, 0);     // Turn off the redraw flag
  601.    
  602.    lResult = DateObj(hDateObj, GET, YEAR, 0);// Add nYear to list box
  603.    if (HIWORD(lResult) != DATE_ERROR)
  604.       {
  605.       wsprintf(szString, "nYear: %d", (WORD) lResult);
  606.       SendMessage(hLB, LB_ADDSTRING, 0, (LONG) ((LPSTR) szString));
  607.       }
  608.    else
  609.       return(0);
  610.                                              // Add nMonth to list box
  611.    lResult = DateObj(hDateObj, GET, MONTH, 0);
  612.    if (HIWORD(lResult) != DATE_ERROR)
  613.       {
  614.       wsprintf(szString, "nMonth: %d", (WORD) lResult);
  615.       SendMessage(hLB, LB_ADDSTRING, 0, (LONG) ((LPSTR) szString));
  616.       }
  617.    else
  618.       return(0);
  619.    lResult = DateObj(hDateObj, GET, DAY, 0); // Add nDay to list box
  620.    if (HIWORD(lResult) != DATE_ERROR)
  621.       {
  622.       wsprintf(szString, "nDay: %d", (WORD) lResult);
  623.       SendMessage(hLB, LB_ADDSTRING, 0, (LONG) ((LPSTR) szString));
  624.       }
  625.    else
  626.       return(0);
  627.                                              // Add nLeapYear to list box
  628.    lResult = DateObj(hDateObj, GET, LEAPYEAR, 0);
  629.    if (HIWORD(lResult) != DATE_ERROR)
  630.       {
  631.       wsprintf(szString, "nLeapYear: %d", (WORD) lResult);
  632.       SendMessage(hLB, LB_ADDSTRING, 0, (LONG) ((LPSTR) szString));
  633.       }
  634.    else
  635.       return(0);
  636.                                              // Add nYearDays to list box
  637.    lResult = DateObj(hDateObj, GET, DAYOFYEAR, 0);
  638.    if (HIWORD(lResult) != DATE_ERROR)
  639.       {
  640.       wsprintf(szString, "nYearDays: %d", (WORD) lResult);
  641.       SendMessage(hLB, LB_ADDSTRING, 0, (LONG) ((LPSTR) szString));
  642.       }
  643.    else
  644.       return(0);
  645.                                              // Add lJulianDate to list box
  646.    lResult = DateObj(hDateObj, GET, JULIANDATE, 0);
  647.    if (HIWORD(lResult) != DATE_ERROR)
  648.       {
  649.       wsprintf(szString, "lJulianDate: %lu", lResult);
  650.       SendMessage(hLB, LB_ADDSTRING, 0, (LONG) ((LPSTR) szString));
  651.       }
  652.    else
  653.       return(0);
  654.    SendMessage(hLB, WM_SETREDRAW, 1, 0);     // Turn on the redraw flag
  655.                                              // Add nDayOfWeek to list box
  656.    lResult = DateObj(hDateObj, GET, DAYOFWEEK, 0);
  657.    if (HIWORD(lResult) != DATE_ERROR)
  658.       {
  659.       wsprintf(szString, "nDayOfWeek: %d", (WORD) lResult);
  660.       SendMessage(hLB, LB_ADDSTRING, 0, (LONG) ((LPSTR) szString));
  661.       }
  662.    else
  663.       return(0);
  664.  
  665.    return(bResult);                          // return BOOL result
  666. }
  667.