Annotation of os232sdk/toolkt20/c/samples/bio/biocmd.c, revision 1.1

1.1     ! root        1: /*  BioDlg() - Dialog Box routine.
        !             2: *
        !             3: *   Created by Microsoft, IBM Corporation, 1990
        !             4: *
        !             5: *   Purpose:
        !             6: *       Allow setting of birthdate and viewing date for biorhythm display.
        !             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):
        !            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.
        !            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: 
        !            59: MRESULT EXPENTRY BioDlg( hDlg, message, mp1, mp2 )
        !            60: HWND    hDlg;
        !            61: USHORT  message;
        !            62: MPARAM  mp1;
        !            63: MPARAM  mp2;
        !            64: {
        !            65:     switch( message ) {
        !            66:         case WM_INITDLG:
        !            67:            InitBioDlg(hDlg);
        !            68:            break;
        !            69: 
        !            70:         case WM_COMMAND:
        !            71:            BioDlgCmd(hDlg, mp1);
        !            72:            break;
        !            73: 
        !            74:         default:
        !            75:             return( WinDefDlgProc( hDlg, message, mp1, mp2 ) );
        !            76: 
        !            77:     }
        !            78:     return 0L;
        !            79: }
        !            80: 
        !            81: 
        !            82: /*  About() - General purpose About dialog box.
        !            83: *
        !            84: *   Purpose:
        !            85: *       Provide program propoganda.
        !            86: *
        !            87: *   Arguments:
        !            88: *       hDlg          - Handle of Dialog Box owning message
        !            89: *       message       - Message itself
        !            90: *       mp1           - Extra message-dependent info
        !            91: *       mp2           - Extra message-dependent info
        !            92: */
        !            93: 
        !            94: MRESULT EXPENTRY About( hWndDlg, message, mp1, mp2 )
        !            95: HWND   hWndDlg;
        !            96: USHORT message;
        !            97: MPARAM  mp1;
        !            98: MPARAM  mp2;
        !            99: {
        !           100:     switch( message )
        !           101:     {
        !           102:       case WM_COMMAND:
        !           103:         switch( LOUSHORT( mp1 ) )
        !           104:         {
        !           105:           case DID_OK:
        !           106:             WinDismissDlg( hWndDlg, TRUE );
        !           107:             break;
        !           108: 
        !           109:           default:
        !           110:             break;
        !           111:         }
        !           112:         break;
        !           113: 
        !           114:       default:
        !           115:         return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) );
        !           116:     }
        !           117:     return( FALSE );
        !           118: }
        !           119: /*
        !           120: */
        !           121: 
        !           122: VOID InitBioDlg(HWND hDlg)
        !           123: {
        !           124: /*
        !           125:      If valid OS2.INI info, fill in birthdate edit fields
        !           126: */
        !           127:     USHORT     year, month;
        !           128:     double      day;
        !           129: 
        !           130:     if (bBorn) {
        !           131:       calendar( Born, (SHORT *)&year, (SHORT *)&month, &day );
        !           132:       WinSetDlgItemShort( hDlg, ID_BDYEAR, year, FALSE );
        !           133:       WinSetDlgItemShort( hDlg, ID_BDMONTH, month, FALSE );
        !           134:       WinSetDlgItemShort( hDlg, ID_BDDAY, (int)day, FALSE );
        !           135:     }
        !           136:     /* Display current date or date highlighted */
        !           137:     calendar( Born+SelectDay, (SHORT *)&year, (SHORT *)&month, &day );
        !           138:     WinSetDlgItemShort( hDlg, ID_YEAR, year, FALSE );
        !           139:     WinSetDlgItemShort( hDlg, ID_MONTH, month, FALSE );
        !           140:     WinSetDlgItemShort( hDlg, ID_DAY, (int)day, FALSE );
        !           141: }
        !           142: /*
        !           143: */
        !           144: 
        !           145: VOID BioDlgCmd( HWND hDlg, MPARAM mp1 )
        !           146: {
        !           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:              PrfWriteProfileString( HINI_USERPROFILE, szAppName, "Year", szBuf );
        !           176:                   sprintf(szBuf, "%d", month);
        !           177:              PrfWriteProfileString( HINI_USERPROFILE, szAppName, "Month", szBuf );
        !           178:                   sprintf(szBuf, "%d", (int)day);
        !           179:              PrfWriteProfileString( HINI_USERPROFILE, 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: }
        !           214: /*
        !           215: */

unix.superglobalmegacorp.com

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