home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDSCANB.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  9KB  |  237 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*         GWSIM - Simulation        */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*          Scan Boundaries          */
  14. /*            dialog box             */
  15. /*                                   */
  16. /*           QuickC/WIN 1.0          */
  17. /*                                   */
  18. /*   (include here compilers that    */
  19. /*   compiled GWSIM successfully)    */
  20. /*                                   */
  21. /*************************************/
  22.  
  23.  
  24. #include <windows.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <math.h>
  28. #include "defines.h"                    /* symbols also used in .DLG files        */
  29. #include "globals.h"                    /* gepasi's own symbols                    */
  30. #include "gwsim.h"                        /* macros, function prototypes, etc.    */
  31. #include "gep2.h"                        /* gepasi's variables                    */
  32. #include "simgvar.h"                    /* global variables                        */
  33. #include "strtbl.h"                        /* symbols for the string table            */
  34.  
  35. #pragma alloc_text( CODE8, EdScanB)
  36.  
  37. BOOL FAR PASCAL EdScanB(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
  38. {
  39.  static csel, nsel;
  40.  static HWND hSelect, hLow, hHigh, hDens, hLog;
  41.  int  i, j, len;
  42.  char buff[128];
  43.  unsigned long d;
  44.  
  45.  switch(Message)
  46.  {
  47.   case WM_INITDIALOG:
  48.    /* allocate memory for the mirror                */
  49.    hScp = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, sizespar );
  50.    if( hScp == NULL )
  51.    {
  52.     LoadString(hInst, IDS_ERR_NOEXEC, szString, sizeof(szString));
  53.     MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  54.     EndDialog(hDlg, FALSE);
  55.     return TRUE;
  56.    }
  57.  
  58.    /* lock the memory block                            */
  59.    scp  = (struct sp huge *) GlobalLock( hScp );
  60.  
  61.    /* copy params to its mirror                                    */
  62.    _fmemcpy( (void __far *) scp,
  63.              (void __far *) spar,
  64.              (size_t) sizespar );
  65.  
  66.    /* get handles to controls                        */
  67.    hSelect = GetDlgItem( hDlg, IDC_SELECT );
  68.    hLow = GetDlgItem( hDlg, IDE_M0 );
  69.    hHigh = GetDlgItem( hDlg, IDE_M1 );
  70.    hDens = GetDlgItem( hDlg, IDE_M2 );
  71.    hLog = GetDlgItem( hDlg, IDC_LOG );
  72.  
  73.    /* initialize hSelect: add all selected elements    */
  74.    for( i=0, lbWidth=0; i<totscan; i++ )
  75.     for( j=0; j<nscanpar; j++ )
  76.      if( (scp[j].idx-1) ==  i )
  77.       AddPLst( hSelect, j, TRUE );
  78.  
  79.    /* select the first element                        */
  80.    nsel = 0;
  81.    SendMessage( hSelect, LB_SETCURSEL, (WORD) nsel, 0 );
  82.    for( i=0; i<nscanpar; i++ )
  83.     if( scp[i].idx-1 == nsel ) csel = i;
  84.  
  85.    /* check the log button if appropriate             */
  86.    i= scp[csel].log;
  87.    SendMessage( hLog, BM_SETCHECK, (WORD) i, 0 );
  88.  
  89.    /* write the numeric values in the edit boxes    */
  90.    gcvt( scp[csel].low, 16, buff );
  91.    SendMessage( hLow, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  92.    gcvt( scp[csel].high, 16, buff );
  93.    SendMessage( hHigh, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  94.    if( options.scan==1 ) ultoa( (int) scp[csel].dens, buff, 10 );
  95.    else ultoa( options.scandens, buff, 10 );
  96.    SendMessage( hDens, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  97.  
  98.    InvalidateRect( hDlg, NULL, FALSE );
  99.    return TRUE;
  100.  
  101.   case WM_COMMAND:
  102.    switch(wParam)
  103.    {
  104.     case IDC_SELECT:
  105.      if( HIWORD( lParam ) == LBN_SELCHANGE )
  106.      {
  107.       /*get the parameters for the old selection    */
  108.       /* check the log button                          */
  109.       scp[csel].log = (int) SendMessage( hLog, BM_GETCHECK, 0, 0 );
  110.       /* read the numeric values from the edit boxes*/
  111.       len = (int) SendMessage( hLow, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  112.       if( len>0 ) scp[csel].low = strtod( buff, NULL );
  113.       if( (scp[csel].low==HUGE_VAL) || (scp[csel].low==-HUGE_VAL)  || (len==0) )
  114.       {
  115.        LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  116.        MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  117.        SendMessage( hSelect, LB_SETCURSEL, (WORD) nsel, 0 );
  118.        SetFocus( hLow );
  119.        return TRUE;
  120.       }
  121.       len = (int) SendMessage( hHigh, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  122.       if( len>0 ) scp[csel].high = strtod( buff, NULL );
  123.       if( (scp[csel].high==HUGE_VAL) || (scp[csel].high==-HUGE_VAL)  || (len==0) )
  124.       {
  125.        LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  126.        MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  127.        SendMessage( hSelect, LB_SETCURSEL, (WORD) nsel, 0 );
  128.        SetFocus( hHigh );
  129.        return TRUE;
  130.       }
  131.       len = (int) SendMessage( hDens, WM_GETTEXT, (WORD) sizeof( buff ), (DWORD)(LPSTR) buff );
  132.       if( len>0 ) d = strtoul( buff, NULL, 10 );
  133.       if( (len==0) || (d==0) )
  134.       {
  135.        LoadString(hInst, IDS_ERR_ZEROBAD, szString, sizeof(szString));
  136.        MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  137.        SendMessage( hSelect, LB_SETCURSEL, (WORD) nsel, 0 );
  138.        SetFocus( hDens );
  139.        return TRUE;
  140.       }
  141.       if( options.scan==1 ) scp[csel].dens = d;
  142.       else options.scandens = d;
  143.  
  144.       /* get the index of the new element selected                    */
  145.       nsel = (int) SendMessage( hSelect, LB_GETCURSEL, 0, 0 );
  146.       if( nsel != LB_ERR )
  147.       {
  148.        for( i=0; i<nscanpar; i++ )
  149.         if( scp[i].idx == nsel+1 ) csel = i;
  150.  
  151.        /* check the log button if appropriate             */
  152.        i= scp[csel].log;
  153.        SendMessage( hLog, BM_SETCHECK, (WORD) i, 0 );
  154.  
  155.        /* write the numeric values in the edit boxes    */
  156.        gcvt( scp[csel].low, 16, buff );
  157.        SendMessage( hLow, WM_SETTEXT, 0,(DWORD)(LPSTR) buff );
  158.        gcvt( scp[csel].high, 16, buff );
  159.        SendMessage( hHigh, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  160.        if( options.scan==1 ) ultoa( scp[csel].dens, buff, 10 );
  161.        else ultoa( options.scandens, buff, 10 );
  162.        SendMessage( hDens, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  163.  
  164.        InvalidateRect( hDlg, NULL, FALSE );
  165.        return TRUE;
  166.       }
  167.      }
  168.      else return FALSE;
  169.  
  170.     case IDC_HELP:            /* Help on this Dialog Box                */
  171.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Scan boundaries" );
  172.      return TRUE;
  173.  
  174.     case IDOK:
  175.      /* check the log button                          */
  176.      scp[csel].log = (int) SendMessage( hLog, BM_GETCHECK, 0, 0 );
  177.      /* read the numeric values from the edit boxes*/
  178.      len = (int) SendMessage( hLow, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  179.      if( len>0 ) scp[csel].low = strtod( buff, NULL );
  180.      if( (scp[csel].low==HUGE_VAL) || (scp[csel].low==-HUGE_VAL)  || (len==0) )
  181.      {
  182.       LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  183.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  184.       SendMessage( hSelect, LB_SETCURSEL, (WORD) nsel, 0 );
  185.       SetFocus( hLow );
  186.       return TRUE;
  187.      }
  188.      len = (int) SendMessage( hHigh, WM_GETTEXT, (WORD) sizeof(buff), (DWORD) (LPSTR) buff );
  189.      if( len>0 ) scp[csel].high = strtod( buff, NULL );
  190.      if( (scp[csel].high==HUGE_VAL) || (scp[csel].high==-HUGE_VAL)  || (len==0) )
  191.      {
  192.       LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  193.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  194.       SendMessage( hSelect, LB_SETCURSEL, (WORD) nsel, 0 );
  195.       SetFocus( hHigh );
  196.       return TRUE;
  197.      }
  198.      len = (int) SendMessage( hDens, WM_GETTEXT, (WORD) sizeof( buff ), (DWORD)(LPSTR) buff );
  199.      if( len>0 ) d = strtoul( buff, NULL, 10 );
  200.      if( (len==0) || (d==0) )
  201.      {
  202.       LoadString(hInst, IDS_ERR_ZEROBAD, szString, sizeof(szString));
  203.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  204.       SendMessage( hSelect, LB_SETCURSEL, (WORD) nsel, 0 );
  205.       SetFocus( hDens );
  206.       return TRUE;
  207.      }
  208.      if( options.scan==1 ) scp[csel].dens = d;
  209.      else options.scandens = d;
  210.  
  211.      /* copy params back from its mirror                                */
  212.      _fmemcpy( (void __far *) spar,
  213.                (void __far *) scp,
  214.                (size_t) sizespar );
  215.      /* unlock and free the mirror memory block             */
  216.      GlobalUnlock( hScp );
  217.      GlobalFree( hScp );
  218.      /* signal that changes have been made                    */
  219.      notsaved = 1;
  220.      EndDialog(hDlg, TRUE);
  221.      return TRUE;
  222.  
  223.     case IDCANCEL:
  224.      /* unlock and free the mirror memory block             */
  225.      GlobalUnlock( hOel );
  226.      GlobalFree( hOel );
  227.      EndDialog(hDlg, FALSE);
  228.      return TRUE;
  229.    }    /* End of WM_COMMAND                                 */
  230.    return FALSE;
  231.  
  232.   default:
  233.    return FALSE;
  234.  }
  235. }
  236.  
  237.