--- pmsdk/samples/bio/biocmd.c 2018/08/09 12:28:13 1.1 +++ pmsdk/samples/bio/biocmd.c 2018/08/09 12:28:33 1.1.1.2 @@ -1,10 +1,9 @@ /* BioDlg() - Dialog Box routine. * -* Created by Microsoft Corp., 1988 +* Created by Microsoft Corporation, 1989 * * Purpose: -* Allow setting of birthdate and day of interest for basing biorhythm -* calculation and display. +* Allow setting of birthdate and viewing date for biorhythm display. * * Arguments: * hDlg - Handle of Dialog Box owning message @@ -13,10 +12,10 @@ * mp2 - Extra message-dependent info * * Globals (modified): -* Born - Bithdate in julian days. Read from OS2.INI. -* SelectDay - Current day being tracked, day is highlighted. Is -* in units of days from birth date. Date of present -* day initially used in WM_CREATE. +* Born - Birthdate in julian days. Read from OS2.INI. +* SelectDay - Current day being tracked, day is highlighted. +* This is stored as # days from birthdate. +* This is initialized to the current date in WM_CREATE. * Day - Day number from date born which is top line being * displayed. Initially three days before SelectDay. * bBorn - Boolean indicating whether valid birtdate entered or @@ -57,93 +56,24 @@ extern long SelectDay, Day; extern double Born; extern BOOL bBorn; -MRESULT FAR PASCAL BioDlg( hDlg, message, mp1, mp2 ) +/* Function prototypes */ +void InitBioDlg(HWND); +void BioDlgCmd(HWND, MPARAM); + +MRESULT CALLBACK BioDlg( hDlg, message, mp1, mp2 ) HWND hDlg; USHORT message; MPARAM mp1; MPARAM mp2; { - USHORT year, month, iDay; - double day; - char szBuf[10]; - switch( message ) { case WM_INITDLG: - /* If valid OS2.INI info, fill in Birth date edit fields */ - if (bBorn) { - calendar( Born, (int *)&year, (int *)&month, &day ); - WinSetDlgItemShort( hDlg, IDBDYEAR, year, FALSE ); - WinSetDlgItemShort( hDlg, IDBDMONTH, month, FALSE ); - WinSetDlgItemShort( hDlg, IDBDDAY, (int)day, FALSE ); - } - /* Display current date or date highlighted */ - calendar( Born+SelectDay, (int *)&year, (int *)&month, &day ); - WinSetDlgItemShort( hDlg, IDYEAR, year, FALSE ); - WinSetDlgItemShort( hDlg, IDMONTH, month, FALSE ); - WinSetDlgItemShort( hDlg, IDDAY, (int)day, FALSE ); - break; + InitBioDlg(hDlg); + break; case WM_COMMAND: - switch( LOUSHORT( mp1 ) ) { - case DID_OK: - /* Get the birthday edit field values */ - WinQueryDlgItemShort( hDlg, IDBDYEAR, &year, FALSE ); - WinQueryDlgItemShort( hDlg, IDBDMONTH, &month, FALSE ); - WinQueryDlgItemShort( hDlg, IDBDDAY, &iDay, FALSE ); - day = (double)iDay; - /* Check that date is within acceptable range */ - if (year<1900 || year>2100) { - WinMessageBox( HWND_DESKTOP, hDlg, - "Dates valid from 1900-2100", - "Birthday!", NULL, - MB_OK | MB_ICONEXCLAMATION ); - break; - } - /* Get julian date of birth date */ - Born = julian( year, month, day ); - - /* Write birth date to OS2.INI if check box checked */ - if (WinSendDlgItemMsg(hDlg, IDOS2INI, BM_QUERYCHECK, 0L, 0L)) { - sprintf(szBuf, "%d", year); - WinWriteProfileString( hAB, szAppName, "Year", szBuf ); - sprintf(szBuf, "%d", month); - WinWriteProfileString( hAB, szAppName, "Month", szBuf ); - sprintf(szBuf, "%d", (int)day); - WinWriteProfileString( hAB, szAppName, "Day", szBuf ); - } - - /* Get selected day of interest edit field values */ - WinQueryDlgItemShort( hDlg, IDYEAR, &year, FALSE ); - WinQueryDlgItemShort( hDlg, IDMONTH, &month, FALSE ); - WinQueryDlgItemShort( hDlg, IDDAY, &iDay, FALSE ); - day = (double)iDay; - /* Check that date is within acceptable range */ - if (year<1900 || year>2100) { - WinMessageBox( HWND_DESKTOP, hDlg, - "Dates valid from 1900-2100", - "Display Date!", NULL, - MB_OK | MB_ICONEXCLAMATION ); - break; - } - - /* Compute number of days since birth */ - SelectDay = (long)(julian( year, month, day ) - Born); - /* Top date of display is 3 days before selected day */ - Day = SelectDay - 3; - /* Got a valid birthdate, enable all routines */ - bBorn = TRUE; - WinDismissDlg( hDlg, TRUE ); - break; - - case DID_CANCEL: - /* Nope! Exit and ignore entries */ - WinDismissDlg( hDlg, FALSE ); - break; - - default: - break; - } - break; + BioDlgCmd(hDlg, mp1); + break; default: return( WinDefDlgProc( hDlg, message, mp1, mp2 ) ); @@ -163,16 +93,9 @@ MPARAM mp2; * message - Message itself * mp1 - Extra message-dependent info * mp2 - Extra message-dependent info -* -* Globals: -* none -* -* Limits: -* N/A -* */ -MRESULT FAR PASCAL About( hWndDlg, message, mp1, mp2 ) +MRESULT CALLBACK About( hWndDlg, message, mp1, mp2 ) HWND hWndDlg; USHORT message; MPARAM mp1; @@ -197,3 +120,94 @@ MPARAM mp2; } return( FALSE ); } + + +void InitBioDlg(HWND hDlg) { +/* + If valid OS2.INI info, fill in birthdate edit fields +*/ + USHORT year, month; + double day; + + if (bBorn) { + calendar( Born, (int *)&year, (int *)&month, &day ); + WinSetDlgItemShort( hDlg, ID_BDYEAR, year, FALSE ); + WinSetDlgItemShort( hDlg, ID_BDMONTH, month, FALSE ); + WinSetDlgItemShort( hDlg, ID_BDDAY, (int)day, FALSE ); + } + /* Display current date or date highlighted */ + calendar( Born+SelectDay, (int *)&year, (int *)&month, &day ); + WinSetDlgItemShort( hDlg, ID_YEAR, year, FALSE ); + WinSetDlgItemShort( hDlg, ID_MONTH, month, FALSE ); + WinSetDlgItemShort( hDlg, ID_DAY, (int)day, FALSE ); +} + + +void BioDlgCmd(HWND hDlg, MPARAM mp1) { +/* + Bio Dialog Box routine WM_COMMAND processor +*/ + USHORT year, month, iDay; + double day; + char szBuf[10]; + + switch( LOUSHORT( mp1 ) ) { + case DID_OK: + /* Get the birthday edit field values */ + WinQueryDlgItemShort( hDlg, ID_BDYEAR, &year, FALSE ); + WinQueryDlgItemShort( hDlg, ID_BDMONTH, &month, FALSE ); + WinQueryDlgItemShort( hDlg, ID_BDDAY, &iDay, FALSE ); + day = (double)iDay; + /* Check that date is within acceptable range */ + if (year<1900 || year>2100) { + WinMessageBox( HWND_DESKTOP, hDlg, + "Dates valid from 1900-2100", + "Birthday!", NULL, + MB_OK | MB_ICONEXCLAMATION ); + break; + } + /* Get julian date of birth date */ + Born = julian( year, month, day ); + + /* Write birth date to OS2.INI if check box checked */ + if (WinSendDlgItemMsg(hDlg, ID_OS2INI, BM_QUERYCHECK, 0L, 0L)) { + sprintf(szBuf, "%d", year); + WinWriteProfileString( hAB, szAppName, "Year", szBuf ); + sprintf(szBuf, "%d", month); + WinWriteProfileString( hAB, szAppName, "Month", szBuf ); + sprintf(szBuf, "%d", (int)day); + WinWriteProfileString( hAB, szAppName, "Day", szBuf ); + } + + /* Get selected day of interest edit field values */ + WinQueryDlgItemShort( hDlg, ID_YEAR, &year, FALSE ); + WinQueryDlgItemShort( hDlg, ID_MONTH, &month, FALSE ); + WinQueryDlgItemShort( hDlg, ID_DAY, &iDay, FALSE ); + day = (double)iDay; + /* Check that date is within acceptable range */ + if (year<1900 || year>2100) { + WinMessageBox( HWND_DESKTOP, hDlg, + "Dates valid from 1900-2100", + "Display Date!", NULL, + MB_OK | MB_ICONEXCLAMATION ); + break; + } + + /* Compute number of days since birth */ + SelectDay = (long)(julian( year, month, day ) - Born); + /* Top date of display is 3 days before selected day */ + Day = SelectDay - 3; + /* Got a valid birthdate, enable all routines */ + bBorn = TRUE; + WinDismissDlg( hDlg, TRUE ); + break; + + case DID_CANCEL: + /* Exit and ignore entries */ + WinDismissDlg( hDlg, FALSE ); + break; + + default: + break; + } +}