home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warptlk3.zip / TOOLKIT / SAMPLES / REXX / API / PMREXX / RXHAFILE.C < prev    next >
C/C++ Source or Header  |  1995-08-24  |  72KB  |  1,250 lines

  1. /* static char *SCCSID = "@(#)rxhafile.c    6.4 92/01/10";               */
  2. /*********************  START OF SPECIFICATIONS  ******************************/
  3. /*                                                                            */
  4. /*   SOURCE FILE NAME:  RXHAFILE.C                                            */
  5. /*                                                                            */
  6. /*   DESCRIPTIVE NAME:  File routines for PMREXX.                             */
  7. /*                                                                            */
  8. /*   COPYRIGHT:         IBM Corporation 1991                                  */
  9. /*                                                                            */
  10. /*   STATUS:            Version 2.00                                          */
  11. /*                                                                            */
  12. /*   FUNCTION:                                                                */
  13. /*           Process the file requests from the user, to allow them to save   */
  14. /*           their output to a file.                                          */
  15. /*                                                                            */
  16. /*   NOTES:                                                                   */
  17. /*      DEPENDENCIES:                                                         */
  18. /*          This function has dependencies on the following                   */
  19. /*      files for compilation.                                                */
  20. /*          os2.h      - All OS/2 specific definitions                        */
  21. /*          rxhdluse.h - necessary equates used by the file procedures        */
  22. /*          pmrexx.h   - global typedefs, defines and prototypes              */
  23. /*          pmrexxio.h - diaglog control defines                              */
  24. /*                                                                            */
  25. /*   PROCEDURES:                                                              */
  26. /*      CheckDosError    - see if a dos error occurred and take action        */
  27. /*      ErrorNotifyProc  - Display error message box                          */
  28. /*      MapButtonText    - Map Text to Buttons                                */
  29. /*      OpenFile         - Open file with given mode                          */
  30. /*      SaveQuit         - Bring up Save/Quit/Cancel Dialog Box               */
  31. /*      SaveQuitDlgProc  - Handle messages for Save/Quit dialog               */
  32. /*      WriteFile        - Write contents of window to given file             */
  33. /*                                                                            */
  34. /*                                                                            */
  35. /***********************  END OF SPECIFICATIONS  ******************************/
  36. /******************************************************************************/
  37. /* Define Constants for additional includes                                   */
  38. /******************************************************************************/
  39.  
  40. #define  INCL_WINCOUNTRY               /* Code page support                   */
  41. #define  INCL_WINDIALOGS               /* Dialog boxes                        */
  42. #define  INCL_WINENTRYFIELDS           /* Entry fields                        */
  43. #define  INCL_WINFRAMEMGR              /* Frame manager                       */
  44. #define  INCL_WINHELP                  /* Help manager definitions            */
  45. #define  INCL_WININPUT                 /* Mouse and keyboard input            */
  46. #define  INCL_WINMESSAGEMGR            /* Message management                  */
  47. #define  INCL_WINSHELLDATA             /* Profile calls                       */
  48. #define  INCL_WINSWITCHLIST            /* Task list calls                     */
  49. #define  INCL_WINTIMER                 /* Timer routines                      */
  50. #define  INCL_WINWINDOWMGR             /* General window management           */
  51. #define  INCL_WINMENUS                 /* Menu controls                       */
  52. #define  INCL_WINMLE                   /* Multiple line edit fields           */
  53. #define  INCL_WINPOINTERS              /* Mouse pointers                      */
  54. #define  INCL_WINSTDFILE               /* Standard File dialog                */
  55. #define  INCL_WINSYS                   /* Sytem Values (and colors)           */
  56. #define  INCL_WINSTATICS               /* Static Controls                     */
  57. #define  INCL_WINMESSAGEMGR            /* Win Message functions               */
  58. #define  INCL_WINSTDFONT               /* Standard Font dialog                */
  59. #define  INCL_DOSQUEUES                /* Queue Support                       */
  60. #define  INCL_DOSERRORS                /* OS/2 Errors                         */
  61. #define  INCL_DOSMISC                  /* for DosError function               */
  62. #define  INCL_DOSFILEMGR               /* File Managment                      */
  63. #define  INCL_DOSSEMAPHORES            /* OS/2 semaphores                     */
  64. #define  INCL_RXSYSEXIT                /* REXX system exits                   */
  65.  
  66. /******************************************************************************/
  67. /* Include required header files                                              */
  68. /******************************************************************************/
  69.  
  70. #include <os2.h>
  71. #include <stdio.h>
  72. #include <stdlib.h>
  73. #include <string.h>
  74. #include <rexxsaa.h>
  75.  
  76. /******************************************************************************/
  77. /* Include Application Header Files                                           */
  78. /******************************************************************************/
  79.  
  80. #include "rxhdluse.h"
  81. #include "pmrexx.h"
  82. #include "pmrexxio.h"
  83.  
  84. /******************************************************************************/
  85. /* Declare character arrays for buttons                                       */
  86. /******************************************************************************/
  87.  
  88. static char ok[BUTTON_TEXT_LENGTH];
  89.  
  90. static char cancel[BUTTON_TEXT_LENGTH];
  91. static char retry[BUTTON_TEXT_LENGTH];
  92. static char abortstr[BUTTON_TEXT_LENGTH];
  93. static char ignore[BUTTON_TEXT_LENGTH];
  94. static char yes[BUTTON_TEXT_LENGTH];
  95. static char no[BUTTON_TEXT_LENGTH];
  96. static char enter[BUTTON_TEXT_LENGTH];
  97.  
  98. static SHORT stringSize = BUTTON_TEXT_LENGTH;/* Define string size            */
  99.  
  100. /************************** START OF SPECIFICATIONS ***************************/
  101. /*                                                                            */
  102. /*   SUBROUTINE NAME: OpenFile                                                */
  103. /*                                                                            */
  104. /*   DESCRIPTIVE NAME:                                                        */
  105. /*               Open a file with the indicated mode.                         */
  106. /*                                                                            */
  107. /*   FUNCTION:                                                                */
  108. /*               Open a file and return the file handle and the action taken  */
  109. /*               to the caller.                                               */
  110. /*                                                                            */
  111. /*   NOTES: None.                                                             */
  112. /*                                                                            */
  113. /*   ENTRY POINT:                                                             */
  114. /*      LINKAGE: int OpenFile                                                 */
  115. /*                                                                            */
  116. /*   INPUT:                                                                   */
  117. /*      PSZ pszFileName      - ptr to ascii string containing file to open    */
  118. /*      PHFILE pFileHandle   - ptr to file handle (returned)                  */
  119. /*      PULONG  pActionTaken - ptr to action taken (returned)                 */
  120. /*      ULONG  iMode         - indicates how to open file                     */
  121. /*                                                                            */
  122. /*   EXIT-NORMAL:                                                             */
  123. /*       Returns 0                                                            */
  124. /*                                                                            */
  125. /*   EXIT-ERROR:                                                              */
  126. /*       Returns ERROR_OPEN_FAILED.                                           */
  127. /*                                                                            */
  128. /*   EFFECTS: None.                                                           */
  129. /*                                                                            */
  130. /*   INTERNAL REFERENCES:                                                     */
  131. /*      ROUTINES:                                                             */
  132. /*        None.                                                               */
  133. /*                                                                            */
  134. /*   EXTERNAL REFERENCES:                                                     */
  135. /*      ROUTINES:                                                             */
  136. /*        DosOpen                                                             */
  137. /*                                                                            */
  138. /**************************** END OF SPECIFICATIONS ***************************/
  139.  
  140. ULONG  OpenFile(PSZ pszFileName,PHFILE pFileHandle,PULONG  pActionTaken,ULONG
  141.                 iMode)
  142. {
  143.   ULONG  DosRC;                        /* Return Code                         */
  144.   ULONG  openflag,openmode;            /* bitmaps for DosOpen                 */
  145.  
  146. /******************************************************************************/
  147. /* Set openflag and openmode based on iMode                                   */
  148. /******************************************************************************/
  149.  
  150.   switch (iMode) {
  151.     case 0 :                           /* Read-only mode                      */
  152.       openflag = OPEN_ACTION_OPEN_IF_EXISTS;/* Open if exists, else fail      */
  153.       openmode = OPEN_SHARE_DENYWRITE; /* R/O access, deny Write              */
  154.       break;
  155.     case 1 :                           /* Write-only mode, new file           */
  156.       openflag = OPEN_ACTION_CREATE_IF_NEW;/* Fail if exists                  */
  157.       openmode = OPEN_FLAGS_WRITE_THROUGH|OPEN_SHARE_DENYWRITE|
  158.           OPEN_ACCESS_WRITEONLY;       /* R/W access, deny Write Synchronous  */
  159.                                        /* Write                               */
  160.       break;
  161.     case 2 :                           /* Write-only mode, replace            */
  162.       openflag = OPEN_ACTION_REPLACE_IF_EXISTS|OPEN_ACTION_CREATE_IF_NEW;/*   */
  163.                                        /* Replace if exists                   */
  164.       openmode = OPEN_FLAGS_WRITE_THROUGH|OPEN_SHARE_DENYWRITE|
  165.           OPEN_ACCESS_WRITEONLY;       /* R/W access, deny Write Synchronous  */
  166.                                        /* Write                               */
  167.       break;
  168.     default  :                         /* Default processing                  */
  169.       return (ERROR_OPEN_FAILED);
  170.   }                                    /* endswitch                           */
  171.  
  172. /******************************************************************************/
  173. /* Call DosOpen to open the file and return the return code                   */
  174. /* from the DosOpen call.                                                     */
  175. /******************************************************************************/
  176.  
  177.   *pActionTaken = 0;
  178.   DosRC = DosOpen(pszFileName,         /* File name                           */
  179.                   pFileHandle,         /* File handle                         */
  180.                   pActionTaken,        /* Action taken                        */
  181.                   0L,                  /* File's new size                     */
  182.                   0,                   /* File attribute bits                 */
  183.                   openflag,            /* Open flag                           */
  184.                   openmode,            /* Open mode                           */
  185.                   0L                   /* Reserved, must be 0                 */
  186.       );
  187.   return (DosRC);
  188. }
  189.  
  190.  
  191. /************************** START OF SPECIFICATIONS ***************************/
  192. /*                                                                            */
  193. /*   SUBROUTINE NAME: WriteFile                                               */
  194. /*                                                                            */
  195. /*   DESCRIPTIVE NAME:                                                        */
  196. /*               Write contents of the window to a file.                      */
  197. /*                                                                            */
  198. /*   FUNCTION:                                                                */
  199. /*               Write contents of the window to a file.                      */
  200. /*                                                                            */
  201. /*                                                                            */
  202. /*   NOTES: None.                                                             */
  203. /*                                                                            */
  204. /*   ENTRY POINT:                                                             */
  205. /*      LINKAGE: BOOL WriteFile                                               */
  206. /*                                                                            */
  207. /*   INPUT:                                                                   */
  208. /*      HWND hwnd       - window handle                                       */
  209. /*      PSZ pszFileName - file name to write to                               */
  210. /*      PSZ pszPgmName  - Rexx program executing                              */
  211. /*      BOOL bConfirm  - indicates if fail or replace on write (TRUE => FAIL) */
  212. /*                                                                            */
  213. /*   EXIT-NORMAL:                                                             */
  214. /*       Returns TRUE.                                                        */
  215. /*                                                                            */
  216. /*   EXIT-ERROR:                                                              */
  217. /*       Returns FALSE.                                                       */
  218. /*                                                                            */
  219. /*   EFFECTS: None.                                                           */
  220. /*                                                                            */
  221. /*   INTERNAL REFERENCES:                                                     */
  222. /*      ROUTINES: OpenFile, CheckDosError                                     */
  223. /*                                                                            */
  224. /*   EXTERNAL REFERENCES:                                                     */
  225. /*      ROUTINES:                                                             */
  226. /*        DosWrite                                                            */
  227. /*        WinLoadString,                                                      */
  228. /*        WinMessageBox,                                                      */
  229. /*        WinSendMsg,                                                         */
  230. /*        WinWindowFromID,                                                    */
  231. /*                                                                            */
  232. /**************************** END OF SPECIFICATIONS ***************************/
  233.  
  234. BOOL WriteFile(HAB  hab,               /* Window Anchor Block                 */
  235.                HWND hwnd,              /* Window Handle                       */
  236.                PSZ  pszFileName,       /* File Name                           */
  237.                PSZ  pszPgmName,        /* Rexx program name                   */
  238.                BOOL bConfirm)          /* Confirm                             */
  239. {
  240.  
  241.   ULONG ulFileSize;                    /* File Size                           */
  242.   ULONG ulFmtSize;                     /* Format Size                         */
  243.   HFILE hFile;                         /* File Handle                         */
  244.   ULONG actionTaken;                   /* Action Taken                        */
  245.   CHAR *buffer;                        /* Pointer to buffer                   */
  246.   ULONG DosRC;                         /* OpenFile Return Code                */
  247.   ULONG UserResponse;                  /* User Response                       */
  248.   ULONG iMode;                         /* OpenFile mode                       */
  249.   ULONG textLen;                       /* Text Length                         */
  250.   LONG  bytesCopied = 0;               /* Number of bytes copied              */
  251.   ULONG usWriteSize;                   /* Write Size                          */
  252.  
  253.   DosError(FERR_DISABLEHARDERR);       /* Disable exception popups            */
  254.  
  255.                                        /* Determine filesize                  */
  256.   ulFileSize = (LONG)WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  257.                                 MLM_QUERYTEXTLENGTH,
  258.                                 (MPARAM)0, (MPARAM)0);
  259.  
  260.   ulFmtSize = (LONG)WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  261.                                MLM_QUERYFORMATTEXTLENGTH, 0,
  262.                                (MPARAM)ulFileSize);
  263.  
  264.    /***************************************************************************/
  265.    /* If file size is greater or equal to limit set text length to            */
  266.    /* FFFE hex otherwise set it to the text format size.                      */
  267.    /***************************************************************************/
  268.  
  269.   textLen = (ulFileSize >= (ULONG)0xffff)?0xfffe:ulFmtSize;
  270.                                        /* Allocate buffer                     */
  271.   DosRC = DosAllocMem((PVOID)&buffer, textLen+1, PAG_COMMIT+PAG_WRITE);
  272.  
  273.    /***************************************************************************/
  274.    /* Determine if a DosError occurred in allocating the buffer               */
  275.    /* and take appropriate action                                             */
  276.    /***************************************************************************/
  277.  
  278.   if ((UserResponse = CheckDosError(hab, hwnd, DosRC, pszPgmName))
  279.       == MBID_CANCEL)
  280.     return (FALSE);
  281.  
  282.                                        /* Import text from window to buffer   */
  283.   WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  284.              MLM_SETIMPORTEXPORT, (MPARAM)buffer, MPFROMSHORT(textLen));
  285.  
  286.   iMode = (bConfirm)?1:2;              /* Set the file mode and user response */
  287.   UserResponse = MBID_RETRY;
  288.  
  289.    /***************************************************************************/
  290.    /* Try to open the file as long as user response is set to retry           */
  291.    /***************************************************************************/
  292.  
  293.   do {
  294.     DosRC = OpenFile((PSZ)pszFileName, &hFile, &actionTaken, iMode);
  295.  
  296.                                        /* If open fails, print message        */
  297.     if ((bConfirm) && (DosRC == ERROR_OPEN_FAILED)) {
  298.  
  299.       CHAR pszOverWrite[MSG_SIZE];     /* Declare variables for messages      */
  300.       CHAR pszOverWriteMsg[MSG_SIZE];
  301.       CHAR pszWarning[MSG_SIZE];
  302.       CHAR pszWarningMsg[MSG_SIZE];
  303.  
  304.                                        /* Load string for overwrite prompt    */
  305.       WinLoadString(hab, (HMODULE)NULL, RXHD_EXISTS,
  306.                     sizeof(pszOverWrite), pszOverWrite);
  307.  
  308.          /*********************************************************************/
  309.          /* Copy overwrite prompt and filename to pszOverWriteMsg             */
  310.          /*********************************************************************/
  311.  
  312.       sprintf(pszOverWriteMsg, pszOverWrite, pszFileName);
  313.  
  314.                                        /* Load Warning message                */
  315.       WinLoadString(hab, (HMODULE)NULL, RXH_WARNING,
  316.                     sizeof(pszWarning), pszWarning);
  317.  
  318.          /*********************************************************************/
  319.          /* Copy warning prompt and program name to pszWarningMsg             */
  320.          /*********************************************************************/
  321.  
  322.       sprintf(pszWarningMsg, pszWarning, pszPgmName);
  323.  
  324.          /*********************************************************************/
  325.          /* Create, display, and operate the message box window               */
  326.          /*********************************************************************/
  327.  
  328.       if (WinMessageBox(HWND_DESKTOP, hwnd, pszOverWriteMsg, pszWarningMsg, 0,
  329.           MB_YESNO|MB_CUAWARNING|MB_MOVEABLE) == MBID_YES) {
  330.  
  331.         bConfirm = FALSE;              /* yes, open specified file            */
  332.         DosRC = OpenFile((PSZ)pszFileName, &hFile, &actionTaken, 2);
  333.       }
  334.  
  335.       else                             /* otherwise return failure            */
  336.         return (FALSE);
  337.     }
  338.                                        /* check and handle errors             */
  339.     if ((UserResponse = CheckDosError(hab, hwnd, DosRC, pszPgmName)) ==
  340.         MBID_CANCEL)
  341.       return (FALSE);
  342.   }
  343.  
  344.      /*************************************************************************/
  345.      /* While the user selects retry, attempt to write to file                */
  346.      /* from the buffer                                                       */
  347.      /*************************************************************************/
  348.  
  349.   while (UserResponse == MBID_RETRY);
  350.  
  351.   do {
  352.  
  353.        /***********************************************************************/
  354.        /* Get the size of the date to be written from the window              */
  355.        /***********************************************************************/
  356.     usWriteSize = (ULONG )WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  357.                                      MLM_EXPORT, &bytesCopied, &ulFileSize);
  358.  
  359.     do {
  360.  
  361.                                        /* Write the buffer to the file        */
  362.       DosRC = DosWrite(hFile, buffer, usWriteSize, &actionTaken);
  363.  
  364.          /*********************************************************************/
  365.          /* If an error occurs, handle the error. Return if canceled          */
  366.          /*********************************************************************/
  367.       if (DosRC) {
  368.  
  369.         if ((UserResponse = CheckDosError(hab, hwnd, DosRC, pszPgmName)) ==
  370.             MBID_CANCEL)
  371.           return (FALSE);
  372.       }
  373.     }
  374.  
  375.     while (UserResponse == MBID_RETRY);/* Do-While loop for retry             */
  376.   }
  377.  
  378.   while (ulFileSize);                  /* Do-While loop for file write        */
  379.  
  380.                                        /* Write EOF marker and do cleanup     */
  381.   DosRC = DosWrite(hFile, "\032", 1, &actionTaken);
  382.  
  383.   DosClose(hFile);
  384.   DosFreeMem(buffer);
  385.  
  386.   DosError(FERR_ENABLEHARDERR);        /* Enable exception popups and return  */
  387.   return (TRUE);
  388. }
  389.  
  390.  
  391. /************************** START OF SPECIFICATIONS ***************************/
  392. /*                                                                            */
  393. /*   SUBROUTINE NAME: CheckDosError                                           */
  394. /*                                                                            */
  395. /*   DESCRIPTIVE NAME:                                                        */
  396. /*               Determine if a DosError occurred, and decide what action     */
  397. /*               to take.                                                     */
  398. /*                                                                            */
  399. /*   FUNCTION:                                                                */
  400. /*               Check the return code and see what sort of action should be  */
  401. /*               taken.                                                       */
  402. /*                                                                            */
  403. /*   NOTES:      MB_?????? constants are used to define which buttons are     */
  404. /*               to be displayed.  This is a fulblown Dialog box , not a      */
  405. /*               message box, so these values mean nothing to the dialog      */
  406. /*               manager here.  We just use them because they are convenient  */
  407. /*               and we use the same text that they would have in a message   */
  408. /*               box.                                                         */
  409. /*                                                                            */
  410. /*   ENTRY POINT:                                                             */
  411. /*      LINKAGE: ULONG  CheckDosError                                         */
  412. /*                                                                            */
  413. /*   INPUT:                                                                   */
  414. /*      HAB  hab  - PM anchor block                                           */
  415. /*      HWND hClientWnd - window handle                                       */
  416. /*      ULONG  DosError    - error code from DosCalls                         */
  417. /*                                                                            */
  418. /*   EXIT-NORMAL:                                                             */
  419. /*       Returns TRUE                                                         */
  420. /*                                                                            */
  421. /*   EXIT-ERROR:                                                              */
  422. /*       Returns FALSE                                                        */
  423. /*                                                                            */
  424. /*   EFFECTS:                                                                 */
  425. /*                                                                            */
  426. /*   INTERNAL REFERENCES:                                                     */
  427. /*      ROUTINES:                                                             */
  428. /*                                                                            */
  429. /*   EXTERNAL REFERENCES:                                                     */
  430. /*      ROUTINES:                                                             */
  431. /*        DosErrClass                                                         */
  432. /*        WinDlgBox                                                           */
  433. /*        WinLoadString                                                       */
  434. /*        WinQueryWindowULong                                                 */
  435. /*                                                                            */
  436. /**************************** END OF SPECIFICATIONS ***************************/
  437.  
  438. ULONG  CheckDosError(HAB hab, HWND hClientWnd,ULONG  DosError,
  439.     PSZ  pszPgmName)
  440. {
  441.   CHAR pszMsg[MSG_SIZE];               /* string for error message            */
  442.   ULONG  usButtons;                    /* bit-map of which buttons to display */
  443.   USHORT usTitle;                      /* Number of title to put on error box */
  444.   CHAR pszTitle[TITLE_SIZE];           /* string of title to put on error box */
  445.   CHAR pszTitleText[TITLE_SIZE];       /* Formatted title text                */
  446.   CHAR pszFormattedErr[MSG_SIZE];      /* contains string version of DosError */
  447.   CHAR pszLocus[MSG_SIZE];             /* string for what device is causing   */
  448.                                        /* error                               */
  449.   CHAR pszClass[MSG_SIZE];             /* what is the class of the error      */
  450.   ULONG  ErrClass;                     /* code for class of error             */
  451.   ULONG  ErrAction;                    /* code for action to take on error    */
  452.   ULONG  ErrLocus;                     /* code for what device is causing the */
  453.                                        /* prob.                               */
  454.   RXHA_ERR rxhaErr;                    /* passed indirectly to ErrorNotifyProc*/
  455.   USHORT usMsgNum;                     /* ID of message string to diplay      */
  456.  
  457.    /***************************************************************************/
  458.    /* Find out which dos error has occured                                    */
  459.    /***************************************************************************/
  460.  
  461.   if (!DosError)
  462.     return (MBID_OK);
  463.  
  464.   else {
  465.     WinSetPointer(HWND_DESKTOP,        /* End wait issued in INITDLG of dialog*/
  466.         WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
  467.  
  468.     switch (DosError) {
  469.       case  ERROR_NOT_READY :          /* Drive is not ready                  */
  470.         usMsgNum = RXH_NOT_READY;
  471.         break;
  472.       case  ERROR_PATH_NOT_FOUND :     /* Path could not be found             */
  473.         usMsgNum = RXH_BAD_PATH;
  474.         break;
  475.       case  ERROR_TOO_MANY_OPEN_FILES :/* No more file handles                */
  476.         usMsgNum = RXH_TOO_MANY_OPEN;
  477.         break;
  478.       case  ERROR_ACCESS_DENIED :      /* System lock in effect               */
  479.         usMsgNum = RXH_ACCESS_DENIED;
  480.         break;
  481.       case  ERROR_INVALID_ACCESS :     /* Bad access attempt                  */
  482.         usMsgNum = RXH_INV_ACCESS;
  483.         break;
  484.       case  ERROR_NOT_DOS_DISK :       /* Unrecognized device                 */
  485.         usMsgNum = RXH_NOT_DISK;
  486.         break;
  487.       case  ERROR_SHARING_VIOLATION :  /* Appl. lock on file                  */
  488.         usMsgNum = RXH_SHARE_VIOL;
  489.         break;
  490.       case  ERROR_SHARING_BUFFER_EXCEEDED :/* Sharing buffer exceeded         */
  491.         usMsgNum = RXH_SHARE_BUFF_EXC;
  492.         break;
  493.       case  ERROR_CANNOT_MAKE :        /* Cannot create the file              */
  494.         usMsgNum = RXH_CANNOT_MAKE;
  495.         break;
  496.       case  ERROR_DRIVE_LOCKED :       /* Drive is locked                     */
  497.         usMsgNum = RXH_DRIVE_LOCKED;
  498.         break;
  499.       case  ERROR_DISK_FULL :          /* No space left                       */
  500.         usMsgNum = RXH_DISK_FULL;
  501.         break;
  502.       case  ERROR_NOT_ENOUGH_MEMORY :  /* Can't allocate memory               */
  503.         usMsgNum = RXH_OUTOF_MEM;
  504.         break;
  505.       case  ERROR_WRITE_PROTECT :      /* Disk is read-only                   */
  506.         usMsgNum = RXH_WRITE_PROT;
  507.         break;
  508.       case  ERROR_FILENAME_EXCED_RANGE :/* Filename is too long               */
  509.         usMsgNum = RXH_NAME_LONG;
  510.         break;
  511.       case  ERROR_INVALID_NAME :       /* Illegal filename                    */
  512.         usMsgNum = RXH_BAD_NAME;
  513.         break;
  514.       default  :
  515.         usMsgNum = RXH_APP_ERROR;      /* generic messages...                 */
  516.         break;
  517.     }
  518.  
  519.       /************************************************************************/
  520.       /* Classify error, and set message box buttons accordingly              */
  521.       /************************************************************************/
  522.  
  523.     usTitle = RXH_WARNING;             /* set default Icon and title          */
  524.     rxhaErr.usIconStyle = SPTR_ICONWARNING;
  525.  
  526.     DosErrClass(DosError, &ErrClass, &ErrAction, &ErrLocus);
  527.  
  528.     switch (ErrAction) {
  529.       case  ERRACT_RETRY :             /* retry immediatly                    */
  530.       case  ERRACT_DLYRET :            /* Delay and retry                     */
  531.       case  ERRACT_USER :              /* Bad user input - get new values     */
  532.       case  ERRACT_INTRET :            /* Retry after user intervention       */
  533.         usButtons = MB_RETRYCANCEL;    /* Retry and Cancel Buttons            */
  534.         break;
  535.  
  536.       case  ERRACT_ABORT :             /* Terminate in an ordely Fashion      */
  537.       case  ERRACT_PANIC :             /* Terminate immediatly                */
  538.         usButtons = MB_CANCEL;         /* Show a Cancel Button                */
  539.         usTitle = RXH_CRITICAL;        /* Critical Title on dlg box           */
  540.         rxhaErr.usIconStyle = SPTR_ICONERROR;/* Error Icon                    */
  541.         break;
  542.  
  543.       case  ERRACT_IGNORE :            /* Ignore Error                        */
  544.         usButtons = MB_ABORTRETRYIGNORE;/* abort retry and ignore buttons     */
  545.         usTitle = RXH_WARNING;         /* title with Warning                  */
  546.         rxhaErr.usIconStyle = SPTR_ICONWARNING;/* warning Icon                */
  547.         break;
  548.  
  549.       default  :
  550.         usButtons = 0;
  551.         break;
  552.     }
  553.  
  554.    /***************************************************************************/
  555.    /* Load the message and title from application resources                   */
  556.    /***************************************************************************/
  557.  
  558.     WinLoadString(hab, (HMODULE)NULL, usTitle, sizeof(pszTitle), pszTitle);
  559.  
  560.     WinLoadString(hab, (HMODULE)NULL, usMsgNum, sizeof(pszMsg), pszMsg);
  561.  
  562.     WinLoadString(hab, (HMODULE)NULL, (USHORT)(RXH_ERRL_START+ErrLocus),
  563.         sizeof(pszLocus), pszLocus);
  564.  
  565.     WinLoadString(hab, (HMODULE)NULL, (USHORT)(RXH_ERRC_START+ErrClass),
  566.         sizeof(pszClass), pszClass);
  567.  
  568.    /***************************************************************************/
  569.    /* Display message to user; return choice to caller                        */
  570.    /***************************************************************************/
  571.  
  572.     sprintf(pszTitleText, pszTitle, pszPgmName);/*  format title              */
  573.     rxhaErr.Title = pszTitleText;      /* pass to ErrorNotifyProc             */
  574.     sprintf(pszFormattedErr, "%i", DosError);/* error number                  */
  575.     rxhaErr.RetCode = pszFormattedErr;
  576.     rxhaErr.Locus = pszLocus;
  577.     rxhaErr.Class = pszClass;
  578.     rxhaErr.message = pszMsg;
  579.     rxhaErr.buttonStyle = usButtons;
  580.     rxhaErr.action = 1;
  581.     rxhaErr.hab = hab;
  582.     {
  583.       ULONG  retVal;
  584.  
  585.                                        /* Start dialog box                    */
  586.       retVal = WinDlgBox(HWND_DESKTOP, hClientWnd, (PFNWP)ErrorNotifyProc,
  587.                          (HMODULE)NULL, RXHD_ERROR, &rxhaErr);
  588.  
  589.       return (rxhaErr.action);         /* return action code                  */
  590.     }
  591.   }                                    /* end: error occurred                 */
  592. }
  593.  
  594.  
  595. /************************** START OF SPECIFICATIONS ***************************/
  596. /*                                                                            */
  597. /*   SUBROUTINE NAME: ErrorNotifyProc                                         */
  598. /*                                                                            */
  599. /*   DESCRIPTIVE NAME:                                                        */
  600. /*               Display error message box.                                   */
  601. /*                                                                            */
  602. /*   FUNCTION:                                                                */
  603. /*               Creates and handles messages for error box.                  */
  604. /*                                                                            */
  605. /*   NOTES:                                                                   */
  606. /*                                                                            */
  607. /*   ENTRY POINT:                                                             */
  608. /*      LINKAGE: MRESULT EXPENTRY ErrorNotifyProc                   */
  609. /*                                                                            */
  610. /*   INPUT:                                                                   */
  611. /*      HWND hwnd      - window handle                                        */
  612. /*      ULONG  msg     - message to process                                   */
  613. /*      MPARAM lParam1 - parameter 1                                          */
  614. /*      MPARAM lParam2 - parameter 2                                          */
  615. /*                                                                            */
  616. /*   The messages handled are:                                                */
  617. /*      WM_INITDLG - initialize the error box                                 */
  618. /*      WM_CLOSE   - close dialog box                                         */
  619. /*      WM_COMMAND - the following WM_COMMAND message are handled             */
  620. /*         BUTTON1 - perform the action assigned to button 1                  */
  621. /*         BUTTON2 - perform the action assigned to button 2                  */
  622. /*         BUTTON3 - perform the action assigned to button 3                  */
  623. /*                                                                            */
  624. /*   EXIT-NORMAL:                                                             */
  625. /*       Returns TRUE                                                         */
  626. /*                                                                            */
  627. /*   EXIT-ERROR:                                                              */
  628. /*       Returns FALSE                                                        */
  629. /*                                                                            */
  630. /*   EFFECTS:                                                                 */
  631. /*                                                                            */
  632. /*   INTERNAL REFERENCES:                                                     */
  633. /*      ROUTINES:                                                             */
  634. /*        InitDlgSysMenu - Remove unwanted options from the system menu       */
  635. /*        MapButtonText  - Change button text to Numbers                      */
  636. /*        PositionDlg    - Position dialog box                                */
  637. /*                                                                            */
  638. /*   EXTERNAL REFERENCES:                                                     */
  639. /*      ROUTINES:                                                             */
  640. /*        WinDefDlgProc                   WinSendMsg                          */
  641. /*        WinDismissDlg                   WinShowWindow                       */
  642. /*        WinLoadString                   WinWindowFromID                     */
  643. /*        WinQueryWindowText              WinSetWindowText                    */
  644. /*                                                                            */
  645. /**************************** END OF SPECIFICATIONS ***************************/
  646.  
  647. MRESULT EXPENTRY ErrorNotifyProc(HWND hwnd,ULONG msg,MPARAM lParam1,MPARAM
  648.                                  lParam2)
  649. {
  650.   static PRXHA_ERR prxhaErr;           /* we only get prxhaerr on a WM_INITDLG*/
  651.                                        /* message                             */
  652.   CHAR buttonText[BUTTON_TEXT_LENGTH]; /* Text of button user clicked on      */
  653.  
  654.  
  655.   switch (msg) {
  656.     case  WM_INITDLG :
  657.  
  658.          /* Start Wait was issued on the call to this dialog                  */
  659.  
  660.       PositionDlg(hwnd);               /* position dialog window              */
  661.       InitDlgSysMenu(hwnd, FALSE);     /* remove items on system menu we dont */
  662.                                        /* want                                */
  663.       prxhaErr = (PRXHA_ERR)lParam2;   /* get all of our data                 */
  664.       WinSetWindowText(hwnd,           /* display title                       */
  665.                        prxhaErr->Title);
  666.                                        /* display error code                  */
  667.       WinSetWindowText(WinWindowFromID(hwnd, (USHORT)RC), prxhaErr->RetCode);
  668.                                        /* display area of error               */
  669.       WinSetWindowText(WinWindowFromID(hwnd, (USHORT)LOCUS), prxhaErr->Locus);
  670.                                        /* display class of error              */
  671.       WinSetWindowText(WinWindowFromID(hwnd, (USHORT)CLASS), prxhaErr->Class);
  672.  
  673.                                        /* display message                     */
  674.       WinSetWindowText(WinWindowFromID(hwnd, (USHORT)MESSAGE),
  675.           prxhaErr->message);
  676.  
  677.       stringSize = BUTTON_TEXT_LENGTH; /* Load the button strings             */
  678.  
  679.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, OK, stringSize, ok);
  680.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, CANCEL, stringSize, cancel);
  681.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, RETRY, stringSize, retry);
  682.       WinLoadString(prxhaErr->hab, prxhaErr->hmod, ABORT, stringSize, abortstr);
  683.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, IGNORE, stringSize, ignore);
  684.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, YES, stringSize, yes);
  685.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, NO, stringSize, no);
  686.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, BENTER, stringSize, enter);
  687.  
  688.       if (ON_m(prxhaErr->buttonStyle, MB_OKCANCEL)) {/* buttons are OK,       */
  689.                                        /* Cancel, and button3 not shown       */
  690.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), ok);
  691.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), cancel);
  692.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  693.       }
  694.  
  695.       else
  696.  
  697.       if (ON_m(prxhaErr->buttonStyle, MB_RETRYCANCEL)) {/* buttons are Retry, */
  698.                                        /* Cancel and Button3 not shown        */
  699.  
  700.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), retry);
  701.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), cancel);
  702.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  703.       }
  704.  
  705.       else
  706.  
  707.       if (ON_m(prxhaErr->buttonStyle, MB_ABORTRETRYIGNORE)) {/* buttons are   */
  708.                                        /* Abort, Retry, and Ignore            */
  709.  
  710.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), abortstr);
  711.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), retry);
  712.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON3), ignore);
  713.       }
  714.  
  715.       else
  716.  
  717.       if (ON_m(prxhaErr->buttonStyle, MB_YESNO)) {/* Buttons are Yes, No and  */
  718.                                        /* button3 not shown                   */
  719.  
  720.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), yes);
  721.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), no);
  722.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  723.       }
  724.  
  725.       else
  726.  
  727.       if (ON_m(prxhaErr->buttonStyle, MB_YESNOCANCEL)) {/* Buttons are Yes No */
  728.                                        /* and Cancel                          */
  729.  
  730.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), yes);
  731.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), no);
  732.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON3), cancel);
  733.       }
  734.  
  735.       else
  736.  
  737.       if (ON_m(prxhaErr->buttonStyle, MB_CANCEL)) {/* Buttons are Cancel and  */
  738.                                        /* buttons 2 & 3 not shown             */
  739.  
  740.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), cancel);
  741.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON2), FALSE);
  742.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  743.       }
  744.  
  745.       else
  746.  
  747.       if (ON_m(prxhaErr->buttonStyle, MB_ENTER)) {/* Buttons are Enter and    */
  748.                                        /* buttons 2 & 3 not shown             */
  749.  
  750.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), enter);
  751.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON2), FALSE);
  752.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  753.       }
  754.  
  755.       else
  756.  
  757.       if (ON_m(prxhaErr->buttonStyle, MB_ENTERCANCEL)) {/* Buttons are Enter, */
  758.                                        /* Cancel and Button 3 not shown       */
  759.  
  760.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), enter);
  761.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), cancel);
  762.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  763.       }
  764.  
  765.       else {                           /* Buttons are OK and buttons 2 & 3 not*/
  766.                                        /* shown                               */
  767.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), ok);
  768.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON2), FALSE);
  769.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  770.       }
  771.       WinSendMsg(WinWindowFromID(hwnd,RXHD_ICON),
  772.                  SM_SETHANDLE,
  773.                  MPFROMHWND(WinQuerySysPointer(HWND_DESKTOP,
  774.                                         prxhaErr->usIconStyle, FALSE) ),
  775.                                         (MPARAM)0);
  776.       WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP,
  777.           SPTR_ARROW, FALSE));
  778.       break;
  779.     case  WM_CLOSE :
  780.       return ((MRESULT)TRUE);
  781.       break;
  782.     case  WM_COMMAND :
  783.  
  784.       switch (LOUSHORT(lParam1)) {
  785.         case  BUTTON1 :
  786.         case  BUTTON2 :
  787.         case  BUTTON3 :                /* read the text from the button       */
  788.           WinQueryWindowText(WinWindowFromID(hwnd, LOUSHORT(lParam1)),
  789.                              stringSize, buttonText);
  790.                                        /* convert text to an number and set   */
  791.                                        /* return code                         */
  792.  
  793.           prxhaErr->action = MapButtonText(buttonText);/* dismiss the dialog  */
  794.                                        /* box                                 */
  795.  
  796.           WinDismissDlg(hwnd, TRUE);
  797.           break;
  798.         default  :
  799.           return (MRESULT)(TRUE);
  800.           break;
  801.       }
  802.       break;
  803.     default  :
  804.       break;
  805.   }
  806.   return (WinDefDlgProc(hwnd, msg, lParam1, lParam2));
  807. }
  808.  
  809.  
  810. /************************** START OF SPECIFICATIONS ***************************/
  811. /*                                                                            */
  812. /*   SUBROUTINE NAME: MapButtonText                                           */
  813. /*                                                                            */
  814. /*   DESCRIPTIVE NAME:                                                        */
  815. /*               Map button text to integers.                                 */
  816. /*                                                                            */
  817. /*   FUNCTION:                                                                */
  818. /*               Compares the input string to the different buttons and       */
  819. /*               returns the button number.                                   */
  820. /*                                                                            */
  821. /*   NOTES:                                                                   */
  822. /*                                                                            */
  823. /*   ENTRY POINT:                                                             */
  824. /*      LINKAGE: ULONG  MapButtonText                                         */
  825. /*                                                                            */
  826. /*   INPUT:                                                                   */
  827. /*      PSZ pszText - ptr to ascii string containing text for button          */
  828. /*                                                                            */
  829. /*   EXIT-NORMAL:                                                             */
  830. /*       Returns action for specified text                                    */
  831. /*                                                                            */
  832. /*   EXIT-ERROR:                                                              */
  833. /*       None.                                                                */
  834. /*                                                                            */
  835. /*   EFFECTS:                                                                 */
  836. /*                                                                            */
  837. /*   INTERNAL REFERENCES:                                                     */
  838. /*      ROUTINES:                                                             */
  839. /*                                                                            */
  840. /*   EXTERNAL REFERENCES:                                                     */
  841. /*      ROUTINES:                                                             */
  842. /*                                                                            */
  843. /**************************** END OF SPECIFICATIONS ***************************/
  844.  
  845. ULONG  MapButtonText(PSZ pszText)
  846. {
  847.  
  848.   if (!strcmp(pszText, ok))            /* Map text to the correct button      */
  849.     return (MBID_OK);
  850.  
  851.   if (!strcmp(pszText, cancel))
  852.     return (MBID_CANCEL);
  853.  
  854.   if (!strcmp(pszText, abortstr))
  855.     return (MBID_ABORT);
  856.  
  857.   if (!strcmp(pszText, retry))
  858.     return (MBID_RETRY);
  859.  
  860.   if (!strcmp(pszText, ignore))
  861.     return (MBID_IGNORE);
  862.  
  863.   if (!strcmp(pszText, yes))
  864.     return (MBID_YES);
  865.  
  866.   if (!strcmp(pszText, no))
  867.     return (MBID_NO);
  868.  
  869.   if (!strcmp(pszText, enter))
  870.     return (MBID_ENTER);
  871. }
  872.  
  873.  
  874. /************************** START OF SPECIFICATIONS ***************************/
  875. /*                                                                            */
  876. /*   SUBROUTINE NAME: SaveQuit                                                */
  877. /*                                                                            */
  878. /*   DESCRIPTIVE NAME:                                                        */
  879. /*               Bring up Save/Quit/Cancel Dialog                             */
  880. /*                                                                            */
  881. /*   FUNCTION:                                                                */
  882. /*               Sets up call to Save/Quit dialog procedure.                  */
  883. /*                                                                            */
  884. /*   NOTES:                                                                   */
  885. /*                                                                            */
  886. /*   ENTRY POINT:                                                             */
  887. /*      LINKAGE: ULONG  SaveQuit                                              */
  888. /*                                                                            */
  889. /*   INPUT:                                                                   */
  890. /*      HAB hab - anchor block handle                                         */
  891. /*      HWND hwnd - window handle                                             */
  892. /*      PSZ pszFName - filename to save output in                             */
  893. /*                                                                            */
  894. /*   EXIT-NORMAL:                                                             */
  895. /*       Returns TRUE if Save/Quit processed                                  */
  896. /*                                                                            */
  897. /*   EXIT-ERROR:                                                              */
  898. /*       Returns FALSE if user hits CANCEL                                    */
  899. /*                                                                            */
  900. /*   EFFECTS:                                                                 */
  901. /*                                                                            */
  902. /*   INTERNAL REFERENCES:                                                     */
  903. /*      ROUTINES:                                                             */
  904. /*                                                                            */
  905. /*   EXTERNAL REFERENCES:                                                     */
  906. /*      ROUTINES:                                                             */
  907. /*        WinLoadString                                                       */
  908. /*        WinDlgBox                                                           */
  909. /*                                                                            */
  910. /**************************** END OF SPECIFICATIONS ***************************/
  911.  
  912. ULONG  SaveQuit(HAB hab,HWND hwnd,PSZ pszFName)
  913. {
  914.   char pszSaveQuitMsg[120];            /* string for save/quit message        */
  915.   char pszMsg[MSG_SIZE];               /* save/quit message with filename     */
  916.                                        /* inserted                            */
  917.   char pszFormFN[FNAME_SIZE];          /* Holds formatted filename            */
  918.   ULONG  UserResponse;                 /* What did they do?                   */
  919.   RX_SAVQUIT_STRUCT rx_SaveQuit;       /* data structure for this dialog box  */
  920.  
  921.  
  922.   if (strlen(pszFName)) {              /* user already entered filename       */
  923.     rx_SaveQuit.bNamedFile = TRUE;
  924.   }
  925.   else {
  926.     rx_SaveQuit.bNamedFile = FALSE;    /* else say it's untitled              */
  927.     WinLoadString(hab,                 /* load the untitled string from       */
  928.                                        /* resource                            */
  929.         (HMODULE)NULL, RX_UNTITLED, FNAME_SIZE, pszFName);
  930.   }
  931.  
  932.   WinLoadString(hab,                   /* load the save/quit message          */
  933.       (HMODULE)NULL, SAVE_QUIT, sizeof(pszSaveQuitMsg), pszSaveQuitMsg);
  934.  
  935.   sprintf(pszMsg, pszSaveQuitMsg, pszFormFN);/* insert the filename into      */
  936.                                        /* message                             */
  937.   rx_SaveQuit.pszSaveQuitMsg = pszMsg; /* load up all the parameters into     */
  938.                                        /* struct                              */
  939.   rx_SaveQuit.hab = hab;
  940.   rx_SaveQuit.hClientWnd = hwnd;
  941.  
  942.   UserResponse =
  943.       WinDlgBox(HWND_DESKTOP,          /* Parent                              */
  944.                 hwnd,                  /* Owner                               */
  945.                 (PFNWP)SaveQuitDlgProc,/* Dlg Proc                            */
  946.                 (HMODULE)NULL,         /* Resource is Loaded                  */
  947.                 RXD_SAVEQUIT,          /* Dialog ID                           */
  948.                 &rx_SaveQuit);         /* Create parms                        */
  949.  
  950.   return (UserResponse);
  951. }
  952.  
  953.  
  954. /************************** START OF SPECIFICATIONS ***************************/
  955. /*                                                                            */
  956. /*   SUBROUTINE NAME: SaveQuitDlgProc                                         */
  957. /*                                                                            */
  958. /*   DESCRIPTIVE NAME:                                                        */
  959. /*               Handle messages for Save/Quit dialog.                        */
  960. /*                                                                            */
  961. /*   FUNCTION:                                                                */
  962. /*               See above.                                                   */
  963. /*                                                                            */
  964. /*   NOTES:                                                                   */
  965. /*                                                                            */
  966. /*   ENTRY POINT:                                                             */
  967. /*      LINKAGE: MRESULT EXPENTRY SaveQuitDlgProc                             */
  968. /*                                                                            */
  969. /*   INPUT:                                                                   */
  970. /*      HWND hDlg - window handle                                             */
  971. /*      USHORT message - message to process                                   */
  972. /*      MPARAM lparm1 - parameter 1                                           */
  973. /*      MPARAM lparm2 - parameter 2                                           */
  974. /*                                                                            */
  975. /*   The messages handled are:                                                */
  976. /*      WM_INITDLG - initialize the error box                                 */
  977. /*      WM_CLOSE   - close dialog box                                         */
  978. /*      WM_COMMAND - the following WM_COMMAND message are handled             */
  979. /*         RXHD_B_SAVE - user pressed SAVE                                    */
  980. /*         RXHD_B_SAVEAS - user pressed SAVEAS                                */
  981. /*         ESCAPE - user pressed CANCEL                                       */
  982. /*         RXHD_B_DISCARD - user pressed DISCARD                              */
  983. /*                                                                            */
  984. /*   EXIT-NORMAL:                                                             */
  985. /*       Returns TRUE if processed correctly                                  */
  986. /*                                                                            */
  987. /*   EXIT-ERROR:                                                              */
  988. /*       Returns FALSE otherwise                                              */
  989. /*                                                                            */
  990. /*   EFFECTS:                                                                 */
  991. /*                                                                            */
  992. /*   INTERNAL REFERENCES:                                                     */
  993. /*      ROUTINES:                                                             */
  994. /*        InitDlgSysMenu                                                      */
  995. /*        PositionDlg                                                         */
  996. /*                                                                            */
  997. /*                                                                            */
  998. /*   EXTERNAL REFERENCES:                                                     */
  999. /*      ROUTINES:                                                             */
  1000. /*        WinDefDlgProc                     WinSendMsg                        */
  1001. /*        WinDismissDlg                     WinSetDlgItemText                 */
  1002. /*        WinEnableWindow                   WinWindowFromID                   */
  1003. /*        WinQuerySysPointer                                                  */
  1004. /*                                                                            */
  1005. /**************************** END OF SPECIFICATIONS ***************************/
  1006.  
  1007. MRESULT EXPENTRY SaveQuitDlgProc(HWND hDlg,ULONG message,MPARAM
  1008.                                  lparm1,MPARAM lparm2)
  1009. {
  1010.   static PRX_SAVQUIT_STRUCT ppszParms; /* static because we only get it once  */
  1011.   MPARAM mpResponse;                   /* return code                         */
  1012.  
  1013. /******************************************************************************/
  1014. /* Retrieve the handles of buttons and list boxes.                            */
  1015. /******************************************************************************/
  1016.  
  1017.   switch (message) {
  1018.     case  WM_INITDLG :                 /* Initialize the Dialog               */
  1019.       PositionDlg(hDlg);               /* position the Dialog box             */
  1020.       InitDlgSysMenu(hDlg, TRUE);      /* strip system menue                  */
  1021.  
  1022.       /************************************************************************/
  1023.       /* Create the Path, and Init Boxes/Buttons                              */
  1024.       /************************************************************************/
  1025.  
  1026.       ppszParms = (PRX_SAVQUIT_STRUCT)lparm2;
  1027.  
  1028.       if (!(ppszParms->bNamedFile)) {  /* Gray Save Button                    */
  1029.         WinEnableWindow(WinWindowFromID(hDlg, (USHORT)RXHD_B_SAVE), FALSE);
  1030.       }
  1031.  
  1032.       /* display the warning ICON                                             */
  1033.  
  1034.       WinSendMsg(WinWindowFromID(hDlg, (USHORT)RXHD_ICON),
  1035.                  SM_SETHANDLE,
  1036.                  MPFROMHWND(WinQuerySysPointer(HWND_DESKTOP,
  1037.                             SPTR_ICONWARNING, FALSE) ), NULL);
  1038.  
  1039.       /* display the save quit message                                        */
  1040.  
  1041.       WinSetDlgItemText(hDlg, RXHD_CHANGETEXT, (*ppszParms).pszSaveQuitMsg);
  1042.       break;
  1043.  
  1044.     case  WM_CLOSE :
  1045.       WinDismissDlg(hDlg, 0);          /* close with a return code of 0       */
  1046.       return ((MRESULT)TRUE);
  1047.       break;
  1048.  
  1049.     case  WM_COMMAND :                 /* Process the Buttons                 */
  1050.  
  1051.       switch (LOUSHORT(lparm1)) {
  1052.         case  RXHD_B_SAVE :            /* send message to Client to get file  */
  1053.                                        /* saved                               */
  1054.           mpResponse = WinSendMsg(ppszParms->hClientWnd, WM_COMMAND,
  1055.                                   MPFROMSHORT(PMRXA_SAVE), 0L);
  1056.  
  1057.           if (mpResponse)              /* if it worked close dialog box       */
  1058.             WinDismissDlg(hDlg, LOUSHORT(mpResponse));
  1059.           break;
  1060.  
  1061.         case  RXHD_B_SAVEAS :          /* let the user pick a new name to save*/
  1062.                                        /* as                                  */
  1063.           mpResponse = WinSendMsg(ppszParms->hClientWnd, WM_COMMAND,
  1064.                                   MPFROMSHORT(PMRXA_SAVEAS), 0L);
  1065.  
  1066.           if                           /* Cancel or error on save as          */
  1067.               ((mpResponse != (MPARAM)0) && (mpResponse != (MPARAM)ESCAPE)) {
  1068.             WinDismissDlg(hDlg, LOUSHORT(mpResponse));
  1069.           }
  1070.           break;
  1071.  
  1072.         case  ESCAPE :                 /* Cancel                              */
  1073.           WinDismissDlg(hDlg, 0);
  1074.           break;
  1075.  
  1076.         case  RXHD_B_DISCARD :         /* discard changes                     */
  1077.           WinDismissDlg(hDlg, 2);
  1078.           break;
  1079.  
  1080.         default  :
  1081.           return (MRESULT)TRUE;
  1082.           break;
  1083.       }
  1084.       break;
  1085.     default  :
  1086.       return (WinDefDlgProc(hDlg, message, lparm1, lparm2));
  1087.   }
  1088.   return ((MRESULT)NULL);
  1089. }
  1090.  
  1091.  
  1092. /************************** START OF SPECIFICATIONS ***************************/
  1093. /*                                                                            */
  1094. /*   SUBROUTINE NAME: PositionDlg                                             */
  1095. /*                                                                            */
  1096. /*   DESCRIPTIVE NAME:                                                        */
  1097. /*               Position the Font dialog.                                    */
  1098. /*                                                                            */
  1099. /*   FUNCTION:                                                                */
  1100. /*               This routine positions the Font dialog relative to the owner */
  1101. /*               window and the desktop.                                      */
  1102. /*                                                                            */
  1103. /*   NOTES:                                                                   */
  1104. /*                                                                            */
  1105. /*   ENTRY POINT:                                                             */
  1106. /*      LINKAGE: PositionDlg(HWND hDlg)                                       */
  1107. /*                                                                            */
  1108. /*   INPUT:                                                                   */
  1109. /*      hDlg            - Handle to the dialog window.                        */
  1110. /*                                                                            */
  1111. /*   EXIT-NORMAL:                                                             */
  1112. /*                                                                            */
  1113. /*   EXIT-ERROR:                                                              */
  1114. /*                                                                            */
  1115. /*   EFFECTS:                                                                 */
  1116. /*                                                                            */
  1117. /*   INTERNAL REFERENCES:                                                     */
  1118. /*      ROUTINES:                                                             */
  1119. /*                                                                            */
  1120. /*   EXTERNAL REFERENCES:                                                     */
  1121. /*      ROUTINES:                                                             */
  1122. /*        WinQuerySysValue                                                    */
  1123. /*        WinQueryWindow                                                      */
  1124. /*        WinQueryWindowPos                                                   */
  1125. /*        WinSetWindowPos                                                     */
  1126. /*                                                                            */
  1127. /**************************** END OF SPECIFICATIONS ***************************/
  1128. BOOL PositionDlg(HWND hDlg)
  1129. {
  1130.    SWP  DlgPos;                        /* Postion of dialog window            */
  1131.    SWP  ClientPos;                     /* Position of client window           */
  1132.    LONG Desktop_cx;                    /* Desktop horizontal coordinate       */
  1133.    LONG Desktop_cy;                    /* Desktop vertical coordinate         */
  1134.  
  1135.                                        /* Get window position                 */
  1136.    WinQueryWindowPos(WinQueryWindow(hDlg, QW_OWNER), &ClientPos);
  1137.    WinQueryWindowPos(hDlg, &DlgPos);
  1138.    Desktop_cx=WinQuerySysValue(HWND_DESKTOP, SV_CXFULLSCREEN);
  1139.    Desktop_cy=WinQuerySysValue(HWND_DESKTOP, SV_CYFULLSCREEN);
  1140.  
  1141.                                        /* calculate y value from Client       */
  1142.    DlgPos.y = (SHORT)(ClientPos.y+ClientPos.cy - DlgPos.cy - DLG_OFFSET_TOP);
  1143.  
  1144.                                        /* Don't let go off the top of the page*/
  1145.    DlgPos.y = (SHORT)( (LONG)(DlgPos.y + DlgPos.cy) > Desktop_cy)
  1146.                      ? (SHORT)(Desktop_cy-(LONG)DlgPos.cy) : DlgPos.y;
  1147.                                        /* Position within bottom too          */
  1148.    DlgPos.y= (SHORT)((DlgPos.y > DLG_OFFSET_Y ) ? DlgPos.y : DLG_OFFSET_Y);
  1149.  
  1150.    DlgPos.x=(ClientPos.cx>DlgPos.cx)   /* Center box under the Title          */
  1151.             ? (ClientPos.x+((ClientPos.cx/(SHORT)2)-(DlgPos.cx/(SHORT)2)))
  1152.             : (ClientPos.x-((DlgPos.cx/(SHORT)2)-(ClientPos.cx/(SHORT)2)));
  1153.  
  1154.    ClientPos.x = (ClientPos.x > 0) ? ClientPos.x : (SHORT)0;
  1155.  
  1156.                                        /* Don't let it go off the left edge   */
  1157.    DlgPos.x= (DlgPos.x > DLG_OFFSET_X ) ? DlgPos.x : (SHORT)DLG_OFFSET_X;
  1158.                                        /* or the right edge                   */
  1159.    DlgPos.x = (SHORT)(((LONG)DlgPos.x + DlgPos.cx) > Desktop_cx)
  1160.               ? (SHORT)(Desktop_cx-(LONG)DlgPos.cx-DLG_OFFSET_X) : DlgPos.x;
  1161.  
  1162.                                        /* Adjust dlgbox, (relative to owner)  */
  1163.    WinSetWindowPos( hDlg,
  1164.                     HWND_TOP,
  1165.                     DlgPos.x, DlgPos.y,
  1166.                     DlgPos.cx, DlgPos.cy,
  1167.                     SWP_SIZE | SWP_MOVE | SWP_ZORDER);
  1168.  
  1169.    return(TRUE);
  1170. }
  1171.  
  1172. /************************** START OF SPECIFICATIONS ***************************/
  1173. /*                                                                            */
  1174. /*   SUBROUTINE NAME: InitDlgSysMenu                                          */
  1175. /*                                                                            */
  1176. /*   DESCRIPTIVE NAME:                                                        */
  1177. /*               Initialize the system menu for dialogues.                    */
  1178. /*                                                                            */
  1179. /*   FUNCTION:                                                                */
  1180. /*               Removes items from the system menu that we don't want.       */
  1181. /*                                                                            */
  1182. /*   NOTES:                                                                   */
  1183. /*                                                                            */
  1184. /*   ENTRY POINT:                                                             */
  1185. /*      LINKAGE: void InitDlgSysMenu                                          */
  1186. /*                                                                            */
  1187. /*   INPUT:                                                                   */
  1188. /*      HWND hDlg   - window handle                                           */
  1189. /*      BOOL bClose - Disable close option (TRUE)                             */
  1190. /*                                                                            */
  1191. /*   EXIT-NORMAL: void                                                        */
  1192. /*                                                                            */
  1193. /*   EXIT-ERROR:  void                                                        */
  1194. /*                                                                            */
  1195. /*   EFFECTS:                                                                 */
  1196. /*                                                                            */
  1197. /*   INTERNAL REFERENCES:                                                     */
  1198. /*      ROUTINES:                                                             */
  1199. /*                                                                            */
  1200. /*   EXTERNAL REFERENCES:                                                     */
  1201. /*      ROUTINES:                                                             */
  1202. /*       WinSendMsg                                                           */
  1203. /*       WinWindowFromID                                                      */
  1204. /*                                                                            */
  1205. /**************************** END OF SPECIFICATIONS ***************************/
  1206.  
  1207. void InitDlgSysMenu( HWND hDlg, BOOL bClose )
  1208. {
  1209.   HWND hSysMenu;                         /* handle to the system menu window */
  1210.  
  1211.                                          /* get handle to system menu        */
  1212.    hSysMenu=WinWindowFromID(hDlg, (USHORT)FID_SYSMENU);
  1213.  
  1214.    /******************************************************************
  1215.    * Remove Items from the system menu that we don't want            *
  1216.    *******************************************************************/
  1217.    WinSendMsg(hSysMenu,                 /* no Switch to ..   option  */
  1218.                MM_DELETEITEM,
  1219.                MPFROM2SHORT(SC_TASKMANAGER,TRUE),
  1220.                MPFROMSHORT(NULL));
  1221.  
  1222.    WinSendMsg(hSysMenu,                /* no Minimize option         */
  1223.                MM_DELETEITEM,
  1224.                MPFROM2SHORT(SC_MINIMIZE,TRUE),
  1225.                MPFROMSHORT(NULL));
  1226.  
  1227.    WinSendMsg(hSysMenu,                /* no Maximize option         */
  1228.                MM_DELETEITEM,
  1229.                MPFROM2SHORT(SC_MAXIMIZE,TRUE),
  1230.                MPFROMSHORT(NULL));
  1231.  
  1232.    WinSendMsg(hSysMenu,                /* no Size option             */
  1233.                MM_DELETEITEM,
  1234.                MPFROM2SHORT(SC_SIZE,TRUE),
  1235.                MPFROMSHORT(NULL));
  1236.  
  1237.    WinSendMsg(hSysMenu,                /* no Restore option          */
  1238.                MM_DELETEITEM,
  1239.                MPFROM2SHORT(SC_RESTORE,TRUE),
  1240.                MPFROMSHORT(NULL));
  1241.  
  1242.  
  1243.    if (!bClose)      /* disable close option if necessary */
  1244.       WinSendMsg (hSysMenu,
  1245.                 MM_SETITEMATTR,
  1246.                 MPFROM2SHORT(SC_CLOSE, TRUE),
  1247.                 MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));
  1248.    return;
  1249. }
  1250.