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

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

unix.superglobalmegacorp.com

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