Annotation of pmsdk/samples/bio/biocmd.c, revision 1.1.1.1

1.1       root        1: /*  BioDlg() - Dialog Box routine.
                      2: *
                      3: *   Created by Microsoft Corp., 1988
                      4: *
                      5: *   Purpose:
                      6: *       Allow setting of birthdate and day of interest for basing biorhythm
                      7: *       calculation and display.
                      8: *
                      9: *   Arguments:
                     10: *       hDlg          - Handle of Dialog Box owning message
                     11: *       message       - Message itself
                     12: *       mp1           - Extra message-dependent info
                     13: *       mp2           - Extra message-dependent info
                     14: *
                     15: *   Globals (modified):
                     16: *       Born          - Bithdate in julian days.  Read from OS2.INI.
                     17: *       SelectDay     - Current day being tracked, day is highlighted.  Is
                     18: *                       in units of days from birth date.  Date of present
                     19: *                       day initially used in WM_CREATE.
                     20: *       Day           - Day number from date born which is top line being
                     21: *                       displayed.  Initially three days before SelectDay.
                     22: *       bBorn         - Boolean indicating whether valid birtdate entered or
                     23: *                       defined in OS2.INI.  Nothing graphed until valid.
                     24: *
                     25: *   Globals (referenced):
                     26: *       hAB           - Handle to the Anchor Block
                     27: *       szAppName[]   - RC file program name (Biorhythm).
                     28: *
                     29: *   Description:
                     30: *       Biorythm cycles start on the date of birth and the state of
                     31: *       of these cycles may be viewed on the selected date.  A check
                     32: *       box is provided to update (record) the birthdate in the WIN.INI
                     33: *       file so that it will be automatically available in subsequent
                     34: *       sessions.
                     35: *
                     36: *   Limits:
                     37: *       Minor error checking is provided when OK is selected to make
                     38: *       sure that the dates specified fall in the 20th and 21st
                     39: *       centuries.  No error checking is attempted to verify correct
                     40: *       month or day of month entries. 
                     41: *
                     42: */
                     43: 
                     44: #define INCL_WIN
                     45: #include <os2.h>
                     46: 
                     47: #include "bio.h"
                     48: #include <math.h>
                     49: #include <stdio.h>
                     50: 
                     51: /* Read-only global variables */
                     52: extern HAB      hAB;
                     53: extern char     szAppName[];
                     54: 
                     55: /* Global variables (modified) */
                     56: extern long     SelectDay, Day;
                     57: extern double   Born;
                     58: extern BOOL     bBorn;
                     59: 
                     60: MRESULT FAR PASCAL BioDlg( hDlg, message, mp1, mp2 )
                     61: HWND    hDlg;
                     62: USHORT  message;
                     63: MPARAM  mp1;
                     64: MPARAM  mp2;
                     65: {
                     66:     USHORT     year, month, iDay;
                     67:     double      day;
                     68:     char        szBuf[10];
                     69: 
                     70:     switch( message ) {
                     71:         case WM_INITDLG:
                     72:            /* If valid OS2.INI info, fill in Birth date edit fields */
                     73:            if (bBorn) {
                     74:             calendar( Born, (int *)&year, (int *)&month, &day );
                     75:             WinSetDlgItemShort( hDlg, IDBDYEAR, year, FALSE );
                     76:              WinSetDlgItemShort( hDlg, IDBDMONTH, month, FALSE );
                     77:              WinSetDlgItemShort( hDlg, IDBDDAY, (int)day, FALSE );
                     78:            }
                     79:            /* Display current date or date highlighted */
                     80:           calendar( Born+SelectDay, (int *)&year, (int *)&month, &day );
                     81:            WinSetDlgItemShort( hDlg, IDYEAR, year, FALSE );
                     82:            WinSetDlgItemShort( hDlg, IDMONTH, month, FALSE );
                     83:            WinSetDlgItemShort( hDlg, IDDAY, (int)day, FALSE );
                     84:            break;
                     85: 
                     86:         case WM_COMMAND:
                     87:             switch( LOUSHORT( mp1 ) ) {
                     88:                 case DID_OK:
                     89:                     /* Get the birthday edit field values */
                     90:                     WinQueryDlgItemShort( hDlg, IDBDYEAR, &year, FALSE );
                     91:                     WinQueryDlgItemShort( hDlg, IDBDMONTH, &month, FALSE );
                     92:                     WinQueryDlgItemShort( hDlg, IDBDDAY, &iDay, FALSE );
                     93:                     day = (double)iDay;
                     94:                     /* Check that date is within acceptable range */
                     95:                     if (year<1900 || year>2100) {
                     96:                        WinMessageBox( HWND_DESKTOP, hDlg,
                     97:                                       "Dates valid from 1900-2100",
                     98:                                       "Birthday!", NULL,
                     99:                                       MB_OK | MB_ICONEXCLAMATION );
                    100:                        break;
                    101:                     }
                    102:                     /* Get julian date of birth date */
                    103:                     Born = julian( year, month, day );
                    104: 
                    105:                     /* Write birth date to OS2.INI if check box checked */
                    106:                     if (WinSendDlgItemMsg(hDlg, IDOS2INI, BM_QUERYCHECK, 0L, 0L)) {
                    107:                       sprintf(szBuf, "%d", year);
                    108:                       WinWriteProfileString( hAB, szAppName, "Year", szBuf );
                    109:                       sprintf(szBuf, "%d", month);
                    110:                       WinWriteProfileString( hAB, szAppName, "Month", szBuf );
                    111:                       sprintf(szBuf, "%d", (int)day);
                    112:                       WinWriteProfileString( hAB, szAppName, "Day", szBuf );
                    113:                     }
                    114:                         
                    115:                     /* Get selected day of interest edit field values */
                    116:                     WinQueryDlgItemShort( hDlg, IDYEAR, &year, FALSE );
                    117:                     WinQueryDlgItemShort( hDlg, IDMONTH, &month, FALSE );
                    118:                     WinQueryDlgItemShort( hDlg, IDDAY, &iDay, FALSE );
                    119:                     day = (double)iDay;
                    120:                     /* Check that date is within acceptable range */
                    121:                     if (year<1900 || year>2100) {
                    122:                        WinMessageBox( HWND_DESKTOP, hDlg,
                    123:                                       "Dates valid from 1900-2100",
                    124:                                       "Display Date!", NULL,
                    125:                                       MB_OK | MB_ICONEXCLAMATION );
                    126:                        break;
                    127:                     }
                    128: 
                    129:                     /* Compute number of days since birth */
                    130:                     SelectDay  = (long)(julian( year, month, day ) - Born);
                    131:                     /* Top date of display is 3 days before selected day */
                    132:                     Day = SelectDay - 3;
                    133:                     /* Got a valid birthdate, enable all routines */
                    134:                     bBorn = TRUE;
                    135:                     WinDismissDlg( hDlg, TRUE );
                    136:                     break;
                    137: 
                    138:                 case DID_CANCEL:
                    139:                     /* Nope! Exit and ignore entries */
                    140:                     WinDismissDlg( hDlg, FALSE );
                    141:                     break;
                    142: 
                    143:                 default:
                    144:                     break;
                    145:             }
                    146:             break;
                    147: 
                    148:         default:
                    149:             return( WinDefDlgProc( hDlg, message, mp1, mp2 ) );
                    150: 
                    151:     }
                    152:     return 0L;
                    153: }
                    154: 
                    155: 
                    156: /*  About() - General purpose About dialog box.
                    157: *
                    158: *   Purpose:
                    159: *       Provide program propoganda.
                    160: *
                    161: *   Arguments:
                    162: *       hDlg          - Handle of Dialog Box owning message
                    163: *       message       - Message itself
                    164: *       mp1           - Extra message-dependent info
                    165: *       mp2           - Extra message-dependent info
                    166: *
                    167: *   Globals:
                    168: *       none
                    169: *
                    170: *   Limits:
                    171: *       N/A
                    172: *
                    173: */
                    174: 
                    175: MRESULT FAR PASCAL About( hWndDlg, message, mp1, mp2 )
                    176: HWND   hWndDlg;
                    177: USHORT message;
                    178: MPARAM  mp1;
                    179: MPARAM  mp2;
                    180: {
                    181:     switch( message )
                    182:     {
                    183:       case WM_COMMAND:
                    184:         switch( LOUSHORT( mp1 ) )
                    185:         {
                    186:           case DID_OK:
                    187:             WinDismissDlg( hWndDlg, TRUE );
                    188:             break;
                    189: 
                    190:           default:
                    191:             break;
                    192:         }
                    193:         break;
                    194: 
                    195:       default:
                    196:         return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) );
                    197:     }
                    198:     return( FALSE );
                    199: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.