home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / BASIC.C next >
C/C++ Source or Header  |  1993-03-08  |  6KB  |  201 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. /*        MS-WINDOWS front end       */
  11. /*                                   */
  12. /*     general windows functions     */
  13. /*                                   */
  14. /*           QuickC/WIN 1.0          */
  15. /*                                   */
  16. /*   (include here compilers that    */
  17. /*   compiled GWSIM successfully)    */
  18. /*                                   */
  19. /*************************************/
  20.  
  21.  
  22. #include <windows.h>
  23. #include "commdlg.h"
  24. #include "strtbl.h"
  25. #include "defines.h"
  26. int        cxChar, cyChar;                /* text scale                           */
  27. WORD    wAdjX, wAdjY;                /* constants to adjust x-y units        */
  28.  
  29. void InitTxtMetrics( HWND hWnd );
  30. int TxtX( int x );
  31. int TxtY( int y );
  32. void InitScrScale( void );
  33. WORD ScrX( int x );
  34. WORD ScrY( int y );
  35. short AskAboutSave( HWND hWnd, HANDLE hInst, char *fn, WORD style );
  36. LPSTR FAR PASCAL GetOFileName( HWND hWnd, LPSTR achFileName, int sizebuff, LPSTR title, LPSTR filter );
  37. LPSTR FAR PASCAL GetSFileName( HWND hWnd, LPSTR achFileName, int sizebuff, LPSTR title, LPSTR filter );
  38. void ErrorHandler( HANDLE hInst, int nRc );
  39.  
  40. #pragma alloc_text( CODE15, InitTxtMetrics, TxtX, TxtY, InitScrScale, ScrX, ScrY, AskAboutSave, GetOFileName, GetSFileName)
  41.  
  42.  
  43. /*
  44.   3 functions to convert coordinates into proper text coordinates. Usage: call
  45.   InitTxtMetrics(hWnd) as early as possible (for example when initializing the instance).
  46.   Then use TxtX( xcoordinate) and TxtY( ycoordinate ) instead of xcoordinate or ycoordinate
  47. */
  48.  
  49. void InitTxtMetrics( HWND hWnd )
  50. {
  51.  HANDLE hDC;
  52.  TEXTMETRIC tm;
  53.  
  54.  hDC = GetDC( hWnd );
  55.  GetTextMetrics( hDC, &tm );
  56.  cxChar = tm.tmAveCharWidth;
  57.  cyChar = tm.tmHeight + tm.tmExternalLeading;
  58.  ReleaseDC( hWnd, hDC );
  59. }
  60.  
  61. int TxtX( int x )
  62. {
  63.  return (x +1) * cxChar;
  64. }
  65.  
  66. int TxtY( int y )
  67. {
  68.  return (y + 1) * cyChar;
  69. }
  70.  
  71.  
  72. /*
  73.   3 functions to convert coordinates into proper screen coordinates. Usage: call InitScr()
  74.   as early as possible (for example when initializing the instance). Then use
  75.   ScrX( xcoordinate) and ScrY( ycoordinate ) instead of xcoordinate or ycoordinate
  76. */
  77.  
  78. void InitScrScale( void )
  79. {
  80.  LONG lDlgBaseUnits;                                    /*dialog base units                     */
  81.  
  82.  lDlgBaseUnits = GetDialogBaseUnits();
  83.  wAdjX = LOWORD(lDlgBaseUnits);
  84.  wAdjY = HIWORD(lDlgBaseUnits);
  85. }
  86.  
  87. WORD ScrX( int x )
  88. {
  89.  return (x * wAdjX)/4;
  90. }
  91.  
  92. WORD ScrY( int y )
  93. {
  94.  return (y * wAdjY)/8;
  95. }
  96.  
  97.  
  98. /*
  99.   a function to ask if the user wants to save before exiting
  100. */
  101. short AskAboutSave( HWND hWnd, HANDLE hInst, char *fn, WORD style )
  102. {
  103.  char buff[256], buff2[128];
  104.  short nRet;
  105.  
  106.  LoadString(hInst, IDS_SAVEQUERY, buff2, sizeof(buff2));
  107.  wsprintf( buff, buff2, (LPSTR) ( fn[0] ? fn : "<untitled>" ) );
  108.  MessageBeep( MB_ICONQUESTION );
  109. #ifdef GWTOP
  110.  nRet = MessageBox( hWnd, buff, (LPSTR) "Topology", style);
  111. #else
  112.  nRet = MessageBox( hWnd, buff, (LPSTR) "Simulation", style);
  113. #endif
  114.  if( (nRet == IDYES) || (nRet == IDOK) )
  115.   SendMessage( hWnd, WM_COMMAND, fn[0] ? IDM_F_SAVE : IDM_F_SAVEAS, 0 );
  116.  return nRet;
  117. }
  118.  
  119. /*
  120.   a function to call the open file common dialog
  121. */
  122.  
  123. LPSTR FAR PASCAL GetOFileName( HWND hWnd, LPSTR achFileName, int sizebuff, LPSTR title, LPSTR filter )
  124. {
  125.     OPENFILENAME    ofn;
  126.  
  127.     /* first fill up the ofn structure */
  128.     ofn.lStructSize = sizeof(OPENFILENAME);
  129.     ofn.hwndOwner = hWnd;
  130.     ofn.lpstrFilter = filter;
  131.     ofn.lpstrCustomFilter = NULL;
  132.     ofn.nFilterIndex = 1;
  133.     *achFileName = '\0';        /* pass in NULL */
  134.     ofn.lpstrFile = achFileName;
  135.     ofn.nMaxFile = sizebuff;
  136.     ofn.lpstrInitialDir = NULL;
  137.     ofn.lpstrTitle = title;
  138.     ofn.lpstrFileTitle = NULL;
  139.     ofn.lpstrDefExt = NULL;
  140.     ofn.Flags = OFN_HIDEREADONLY |
  141.                 OFN_PATHMUSTEXIST;
  142.     if (  GetOpenFileName( (LPOPENFILENAME) &ofn ) ) return achFileName;
  143.     else return NULL;
  144. }
  145.  
  146. /*
  147.   a function to call the save file common dialog
  148. */
  149.  
  150. LPSTR FAR PASCAL GetSFileName( HWND hWnd, LPSTR achFileName, int sizebuff,
  151.                                LPSTR title, LPSTR filter )
  152. {
  153.     OPENFILENAME    ofn;
  154.  
  155.     /* first fill up the ofn structure */
  156.     ofn.lStructSize = sizeof(OPENFILENAME);
  157.     ofn.hwndOwner = hWnd;
  158.     ofn.lpstrFilter = filter;
  159.     ofn.lpstrCustomFilter = NULL;
  160.     ofn.nFilterIndex = 1;
  161.     /**achFileName = '\0';        pass in NULL */
  162.     ofn.lpstrFile = achFileName;
  163.     ofn.nMaxFile = sizebuff;
  164.     ofn.lpstrInitialDir = NULL;
  165.     ofn.lpstrTitle = title;
  166.     ofn.lpstrFileTitle = NULL;
  167.     ofn.lpstrDefExt = NULL;
  168.     ofn.Flags = OFN_HIDEREADONLY |
  169.                 OFN_NOREADONLYRETURN |
  170.                 OFN_OVERWRITEPROMPT |
  171.                 OFN_PATHMUSTEXIST;
  172.     if (  GetSaveFileName( (LPOPENFILENAME) &ofn ) ) return achFileName;
  173.     else return NULL;
  174. }
  175.  
  176. void ErrorHandler( HANDLE hInst, int nRc )
  177. {
  178.  char szString[128];                    /* variable to load resource strings    */
  179.  
  180.  if( nRc < 32 )
  181.  switch( nRc )
  182.  {
  183.   case 0:
  184.    LoadString( hInst, IDS_ERR_NOEXEC, szString, sizeof(szString) );
  185.    MessageBeep( MB_ICONEXCLAMATION );
  186.    MessageBox( NULL, szString, NULL, MB_ICONEXCLAMATION );
  187.    break;
  188.   case 2:
  189.   case 3:
  190.    LoadString( hInst, IDS_ERR_BADCONFIG, szString, sizeof(szString) );
  191.    MessageBeep( MB_ICONEXCLAMATION );
  192.    MessageBox( NULL, szString, NULL, MB_ICONEXCLAMATION );
  193.    break;
  194.   default:
  195.    LoadString( hInst, IDS_ERR_UNDEF, szString, sizeof(szString) );
  196.    MessageBeep( MB_ICONEXCLAMATION );
  197.    MessageBox( NULL, szString, NULL, MB_ICONEXCLAMATION );
  198.  }
  199.  return;
  200. }
  201.