home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / graphic / fractint / sources / tool1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-20  |  3.9 KB  |  108 lines

  1. /*
  2.     TOOL1.C -- More commonly used library routines
  3.     Created by Microsoft Corporation, 1989
  4. */
  5.  
  6. #include "tool.h"
  7.  
  8. /***************************************************************************\
  9. * Merges sz[idMes1] and szText1 and displays a message box using
  10. * the wStyle. Use caption title provided by szText2.
  11. * Returns the answer from the message box (MBID_OK, MBID_CANCEL).
  12. \***************************************************************************/
  13.  
  14. int EXPENTRY AlertBox (HWND hwnd, int idMes, PSZ lpszText1,
  15.                PSZ lpszText2, USHORT idHelp, USHORT wStyle)
  16.     {
  17.     char szMessage [MAXMESSAGELENGTH];
  18.  
  19.     MergeStrings((PSZ)vrgsz[idMes], lpszText1, (PSZ)szMessage);
  20.     if (idHelp != NULL)
  21.         wStyle |= MB_HELP;
  22.     return (WinMessageBox (HWND_DESKTOP, hwnd, (PSZ)szMessage, lpszText2,
  23.                            idHelp, wStyle));
  24.     }
  25.  
  26.  
  27. /***************************************************************************\
  28. * Scan szSrc for merge spec. If found, insert string szMerge at that point.
  29. * Then append rest of szSrc NOTE! Merge spec guaranteed to be two chars.
  30. * returns TRUE if it does a merge, false otherwise.
  31. \***************************************************************************/
  32.  
  33. BOOL EXPENTRY MergeStrings(PSZ lpszSrc, PSZ lpszMerge, PSZ lpszDst)
  34.     {
  35.     /* Find merge spec if there is one. */
  36.     while (*(unsigned far *)lpszSrc != *(unsigned *)vrgsz[IDS_MERGE1])
  37.         {
  38.         *lpszDst++ = *lpszSrc;
  39.         /* If we reach end of string before merge spec, just return. */
  40.         if (!*lpszSrc++)
  41.             return FALSE;
  42.         }
  43.  
  44.     /* If merge spec found, insert sz2 there. (check for null merge string */
  45.     if (lpszMerge)
  46.         {
  47.         while (*lpszMerge)
  48.             *lpszDst++ = *lpszMerge++;
  49.         }
  50.  
  51.     /* Jump over merge spec */
  52.     lpszSrc++,lpszSrc++;
  53.  
  54.     /* Now append rest of Src String */
  55.     while (*lpszDst++ = *lpszSrc++);
  56.     return TRUE;
  57.     }
  58.  
  59.  
  60.  
  61. /****************************************************************************\
  62. * This function invokes either an Open or Save dialog box.
  63. *     (lpdlf->rgbAction == DLG_OPENDLG)  -->  invoke Open dlgBox
  64. *     (lpdlf->rgbAction == DLG_SAVEDLG)  -->  invoke Save dlbBox
  65. *
  66. * Unless DLG_NOSAVE is specified, the file is opened and left open.
  67. *
  68. * Return values are:
  69. *     TDF_INVALID - Library error (internal error),
  70. *     TDF_ERRMEM  - Out of memory error
  71. *     TDF_NOOPEN  - User hits cancel
  72. *   specific to DLG_OPEN:
  73. *     TDF_NEWOPEN - Created new file
  74. *     TDF_OLDOPEN - Opened existing file
  75. *   specific to DLG_SAVE:
  76. *     TDF_NEWSAVE - user wants to save to a new file
  77. *     TDF_OLDSAVE - user wants to save over existing file
  78. *   specific to DLG_NOSAVE:
  79. *     TDF_NEWSAVE - user wants to save to a new file
  80. *     TDF_OLDSAVE - user wants to save over existing file
  81. \****************************************************************************/
  82.  
  83. int EXPENTRY DlgFile(HWND hwnd, PDLF pdlf)
  84.     {
  85.     /* create dialog box */
  86.     if (pdlf->rgbAction & DLG_SAVEDLG)
  87.         return WinDlgBox(HWND_DESKTOP, hwnd, DlgSaveAsWndProc, vhModule,
  88.                          IDD_SAVEAS, (PSZ)pdlf);
  89.     else
  90.         return WinDlgBox(HWND_DESKTOP, hwnd, DlgOpenWndProc, vhModule,
  91.                          IDD_OPEN, (PSZ)pdlf);
  92.     }
  93.  
  94. /**************************************************************************\
  95. * This function initializes the DLF structure
  96. \**************************************************************************/
  97. void EXPENTRY SetupDLF(PDLF pdlf, int iAction, PHFILE phFile,
  98.                PSZ Extension, PSZ AppName, PSZ pszInTitle,
  99.                PSZ pszInInstructions ) {
  100.     pdlf->pszExt = Extension;
  101.     pdlf->rgbFlags = ATTRDIRLIST;
  102.     pdlf->phFile = phFile;
  103.     pdlf->pszAppName = AppName;
  104.     pdlf->rgbAction = iAction;
  105.     pdlf->pszTitle = pszInTitle;
  106.     pdlf->pszInstructions = pszInInstructions;
  107. }
  108.