home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / PMF300.ZIP / COPYDLGS.C next >
C/C++ Source or Header  |  1993-02-06  |  31KB  |  1,040 lines

  1. /*
  2.            copydlgs.c
  3.            
  4.            dialog box routines for pmfloppy
  5.  
  6.            G. Bryant, 1990,1993
  7.            Delta Music Systems
  8.            Released to the public domain
  9.  
  10.    
  11.   Change Log
  12.  
  13.    6-Jun-90   Change ParseFileName to return different value for empty
  14.               file Name -vs- invalid file name.  change SELECT to ENTER
  15.               for IDD_DI_DIRS field in load and save.
  16.    8-Jun-90   Correct the busy check for Write
  17.    5-Feb-93   Port to OS/2 2.0-C Set/2
  18. */
  19.  
  20.  
  21.  
  22.  
  23. #define INCL_PM
  24. #define INCL_DOSERRORS
  25. #define INCL_BASE
  26. #define INCL_DOSDEVIOCTL
  27. #define INCL_WININPUT
  28. #include <os2.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <ctype.h>
  32. #include "pmfloppy.h"
  33. #include "DskIm.h"
  34.  
  35. // external function prototypes
  36. extern VOID   PutBox(PSZ, PSZ);
  37.  
  38.  
  39. // global function prototypes
  40. FNWP ReadDlgProc;
  41. FNWP WriteDlgProc;
  42. FNWP DeleteDlgProc;
  43. FNWP LoadDlgProc;
  44. FNWP SaveDlgProc;
  45. FNWP CompDlgProc;
  46. FNWP AboutDlgProc;
  47.  
  48. // local function prototypes
  49. VOID   GetImageList(HWND, USHORT, USHORT);
  50. VOID   GetDirList(HWND, CHAR *);
  51. VOID   GetFileList(HWND);
  52. USHORT SetBox(HWND, MPARAM);
  53. USHORT SetEdit(HWND, USHORT);
  54. BOOL   SetDrive(HWND, USHORT);
  55. BOOL   ParseFileName (CHAR *, CHAR *);
  56. BOOL   CheckLSParms(HWND, USHORT);
  57.  
  58. // PM vbls
  59. extern HWND   hWndFrame ;
  60.  
  61. // User response vbls
  62. extern DskImage ImageBuffers[NUM_IMAGES];
  63. extern USHORT   BufferNum;
  64. extern USHORT   CompNum;
  65.  
  66.  
  67. // set up image list and edit boxes
  68. VOID GetImageList(HWND hwnd, USHORT EditB, USHORT ListB) {
  69.  
  70. ULONG curBuff;
  71.  
  72.   for (curBuff=0;
  73.        (curBuff < NUM_IMAGES) &&
  74.         (ImageBuffers[curBuff].BufferName[0] != '\0');
  75.        curBuff++) {
  76.     WinSendDlgItemMsg(hwnd,
  77.                       ListB,
  78.                       LM_INSERTITEM,
  79.                       MPFROMLONG(LIT_END),
  80.                       MPFROMP(ImageBuffers[curBuff].BufferName));
  81.   }
  82.   curBuff = 0;
  83.  
  84.   WinSendDlgItemMsg(hwnd,
  85.                     EditB,
  86.                     EM_SETTEXTLIMIT,
  87.                     MPFROMLONG(BUFFERNMSZ),
  88.                     (MPARAM)0);
  89.  
  90.   WinSetDlgItemText(hwnd, EditB, ImageBuffers[curBuff].BufferName);
  91.   return;
  92. } // GetImageList
  93.  
  94.  
  95. //
  96. // return the buffer number of the selected image
  97. //
  98. USHORT SetBox(HWND hwnd, MPARAM mp1) {
  99.  
  100. ULONG curBuff;
  101. SHORT  Select;
  102. CHAR   curBuffName[BUFFERNMSZ];
  103.  
  104.   // get the selection number
  105.   Select = (USHORT) WinSendDlgItemMsg(hwnd,
  106.                                       SHORT1FROMMP(mp1),
  107.                                       LM_QUERYSELECTION,
  108.                                       (MPARAM)0,
  109.                                       (MPARAM)0);
  110.   // get the selection text
  111.   WinSendDlgItemMsg(hwnd,
  112.                     SHORT1FROMMP(mp1),
  113.                     LM_QUERYITEMTEXT,
  114.                     MPFROM2SHORT(Select,BUFFERNMSZ),
  115.                     MPFROMP(curBuffName));
  116.   // get the buffer number
  117.   for (curBuff=0;
  118.        (curBuff < NUM_IMAGES) &&
  119.        (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  120.        curBuff++) ;
  121.  
  122.   return(curBuff);
  123. } // SetBox
  124.  
  125.  
  126. // Set the drive letter - returns true if illegal value
  127. BOOL SetDrive(HWND hwnd, USHORT curBuff) {
  128.  
  129.   WinQueryDlgItemText(hwnd,
  130.                       IDD_DI_DRV,
  131.                       2,
  132.                       ImageBuffers[curBuff].DriveID);
  133.   ImageBuffers[curBuff].DriveID[0] = (CHAR) toupper(ImageBuffers[curBuff].DriveID[0]);
  134.   if (!isupper((USHORT) ImageBuffers[curBuff].DriveID[0])) {
  135.     PutBox("Destination Drive must be a drive letter","e.g. A");
  136.     return(TRUE);
  137.   }
  138.   return(FALSE);
  139. } // SetDrive
  140.  
  141.  
  142.  
  143. //  ReadDlgProc  --  Disk Read dialog procedure.
  144. //
  145. //  Output:  ReadDrive  --  Global name of selected drive
  146. MRESULT ReadDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  147. {
  148.  
  149. USHORT curChar;
  150. ULONG  curBuff;
  151. CHAR   curBuffName[BUFFERNMSZ];
  152. USHORT NameLen;
  153.  
  154.   switch (id)    {
  155.     case WM_INITDLG:
  156.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  157.       WinSendDlgItemMsg(hwnd,
  158.                         IDD_DI_DRV,
  159.                         EM_SETTEXTLIMIT,
  160.                         MPFROMLONG(1),
  161.                         (MPARAM)0);
  162.       return(0);
  163.  
  164.     case WM_CONTROL:  // get the button that was clicked
  165.       if (SHORT1FROMMP(mp1) == IDD_DI_BOX) {
  166.         curBuff = SetBox(hwnd, mp1);
  167.         switch (SHORT2FROMMP(mp1)) {
  168.           case LN_SELECT:
  169.             WinSetDlgItemText(hwnd,
  170.                               IDD_DI_FLD,
  171.                               ImageBuffers[curBuff].BufferName);
  172.             return(0);
  173.           case LN_ENTER:
  174.             if (SetDrive(hwnd, curBuff)) return(0);
  175.             if (ImageBuffers[curBuff].Busy) {
  176.               PutBox("That image is busy -","please select another");
  177.             }
  178.             else
  179.             {
  180.               ImageBuffers[curBuff].Busy = BUSY_READ;
  181.               BufferNum = curBuff;
  182.               WinDismissDlg(hwnd, TRUE);
  183.             }
  184.             return(0);
  185.         }
  186.  
  187.       }
  188.         return(0);
  189.  
  190.     case WM_COMMAND:
  191.       switch (COMMANDMSG(&id)->cmd)
  192.           {
  193.           case DID_OK:
  194.           NameLen = WinQueryDlgItemText(hwnd,
  195.                                         IDD_DI_FLD,
  196.                                         BUFFERNMSZ,
  197.                                         curBuffName);
  198.  
  199.           if (NameLen == 0) {
  200.             PutBox("You must enter a buffer name,","or select 'Cancel'");
  201.             return(0);
  202.           }
  203.  
  204.           for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  205.             curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  206.  
  207.           for (curBuff=0;
  208.                (curBuff < NUM_IMAGES) &&
  209.                (ImageBuffers[curBuff].BufferName[0] != '\0') &&
  210.                (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  211.                curBuff++) ;
  212.  
  213.           if (curBuff < NUM_IMAGES) {
  214.             if (SetDrive(hwnd, curBuff)) return(0);
  215.             if (ImageBuffers[curBuff].Busy) {
  216.               PutBox("That image is busy -","please select another");
  217.             }
  218.             else {
  219.               ImageBuffers[curBuff].Busy = BUSY_READ;
  220.               strncpy(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ);
  221.               BufferNum = curBuff;
  222.               WinDismissDlg(hwnd, TRUE);
  223.             }
  224.  
  225.           }
  226.           else {
  227.             PutBox("No image buffers left","(try deleting some)");
  228.           }
  229.           return(0);
  230.  
  231.  
  232.         case DID_CANCEL:
  233.             WinDismissDlg(hwnd, FALSE);
  234.           return(0);
  235.       } // switch on commandID
  236.         break;
  237.     } // switch on msgID
  238.  
  239.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  240. } // ReadDlgProc
  241.  
  242.  
  243. //  WriteDlgProc  --  Disk Write dialog procedure.
  244. //
  245. //  Output:  WriteDrive  --  Global name of selected drive
  246. MRESULT WriteDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  247. {
  248.  
  249. USHORT NameLen;
  250. USHORT curChar;
  251. USHORT curBuff;
  252. static CHAR   curBuffName[BUFFERNMSZ];
  253. static USHORT FormOpt;
  254.  
  255.   switch (id)
  256.     {
  257.     case WM_INITDLG:
  258.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  259.       WinSendDlgItemMsg(hwnd,
  260.                         IDD_DI_DRV,
  261.                         EM_SETTEXTLIMIT,
  262.                         MPFROM2SHORT(1,0),
  263.                         NULL);
  264.       WinSendDlgItemMsg(hwnd,
  265.                         IDD_WRF_MAYBE,
  266.                         BM_SETCHECK,
  267.                         MPFROMSHORT(1),
  268.                         NULL);
  269.       FormOpt = IDD_WRF_MAYBE;
  270.       return(0);
  271.  
  272.     case WM_CONTROL:  // get the button that was clicked
  273.       if (SHORT1FROMMP(mp1) == IDD_DI_BOX) {
  274.         curBuff = SetBox(hwnd, mp1);
  275.         switch (SHORT2FROMMP(mp1)) {
  276.           case LN_SELECT:
  277.             WinSetDlgItemText(hwnd,
  278.                               IDD_DI_FLD,
  279.                               ImageBuffers[curBuff].BufferName);
  280.             return(0);
  281.           case LN_ENTER:
  282.             if (SetDrive(hwnd, curBuff)) return(0);
  283.             if (ImageBuffers[curBuff].Busy) {
  284.               PutBox("That image is busy -","please select another");
  285.             }
  286.             else {
  287.               ImageBuffers[curBuff].Busy = BUSY_WRITE;
  288.               ImageBuffers[curBuff].FormatOptions = FormOpt;
  289.               BufferNum = curBuff;
  290.               WinDismissDlg(hwnd, TRUE);
  291.             }
  292.             return(0);
  293.         }
  294.  
  295.       }
  296.       else if ((SHORT1FROMMP(mp1) == IDD_WRF_NEVER) ||
  297.                (SHORT1FROMMP(mp1) == IDD_WRF_MAYBE) ||
  298.                (SHORT1FROMMP(mp1) == IDD_WRF_ALWAYS))
  299.         FormOpt = SHORT1FROMMP(mp1);
  300.         return(0);
  301.  
  302.     case WM_COMMAND:
  303.       switch (COMMANDMSG(&id)->cmd)
  304.           {
  305.           case DID_OK:
  306.           NameLen = WinQueryDlgItemText(hwnd,
  307.                                         IDD_DI_FLD,
  308.                                         BUFFERNMSZ,
  309.                                         curBuffName);
  310.  
  311.           for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  312.             curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  313.  
  314.           for (curBuff=0;
  315.                (curBuff < NUM_IMAGES) &&
  316.                (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  317.                curBuff++) ;
  318.  
  319.           if ((curBuff < NUM_IMAGES) && (NameLen > 0)) {
  320.             if (SetDrive(hwnd, curBuff)) return(0);
  321.             if (ImageBuffers[curBuff].Busy) {
  322.               PutBox("That image is busy -","please select another");
  323.             }
  324.             else {
  325.               ImageBuffers[curBuff].Busy = BUSY_WRITE;
  326.               strncpy(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ);
  327.               ImageBuffers[curBuff].FormatOptions = FormOpt;
  328.               BufferNum = curBuff;
  329.               WinDismissDlg(hwnd, TRUE);
  330.             }
  331.           }
  332.           else {
  333.             PutBox("You must select an existing","image buffer");
  334.  
  335.           }
  336.           return(0);
  337.  
  338.         case DID_CANCEL:
  339.             WinDismissDlg(hwnd, FALSE);
  340.           return(0);
  341.       } // switch on commandID
  342.         break;
  343.     } // switch on msgID
  344.  
  345.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  346. } // WriteDlgProc
  347.  
  348.  
  349.  
  350. //  DeleteDlgProc  --  Image Buffer Delete dialog procedure.
  351. //
  352. MRESULT DeleteDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  353. {
  354.  
  355. USHORT NameLen;
  356. USHORT curChar;
  357. USHORT curBuff;
  358. CHAR   curBuffName[BUFFERNMSZ];
  359.  
  360.   switch (id)
  361.     {
  362.     case WM_INITDLG:
  363.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  364.       return(0);
  365.  
  366.     case WM_CONTROL:  // get the button that was clicked
  367.       if (SHORT1FROMMP(mp1) == IDD_DI_BOX) {
  368.         curBuff = SetBox(hwnd, mp1);
  369.         switch (SHORT2FROMMP(mp1)) {
  370.           case LN_SELECT:
  371.             WinSetDlgItemText(hwnd,
  372.                               IDD_DI_FLD,
  373.                               ImageBuffers[curBuff].BufferName);
  374.             return(0);
  375.           case LN_ENTER:
  376.             if (ImageBuffers[curBuff].Busy)
  377.               PutBox("That buffer is in use.","");
  378.             else {
  379.               // free the memory used by that buffer and coalesce the list
  380.               free(ImageBuffers[curBuff].DskSel);
  381.               free(ImageBuffers[curBuff].DskLayout);
  382.               while (((curBuff+1) < NUM_IMAGES) &&
  383.                      (ImageBuffers[curBuff].BufferName[0] != '\0')) {
  384.                 ImageBuffers[curBuff]  = ImageBuffers[curBuff+1];
  385.                 curBuff++;
  386.               }
  387.               WinDismissDlg(hwnd, TRUE);
  388.             }
  389.         }
  390.  
  391.       }
  392.         return(0);
  393.  
  394.     case WM_COMMAND:
  395.       switch (COMMANDMSG(&id)->cmd)
  396.           {
  397.           case DID_OK:
  398.           NameLen = WinQueryDlgItemText(hwnd,
  399.                                         IDD_DI_FLD,
  400.                                         BUFFERNMSZ,
  401.                                         curBuffName);
  402.  
  403.           for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  404.             curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  405.  
  406.           for (curBuff=0;
  407.                (curBuff < NUM_IMAGES) &&
  408.                (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  409.                curBuff++) ;
  410.  
  411.           if ((curBuff < NUM_IMAGES) && (NameLen > 0)) {
  412.             if (ImageBuffers[curBuff].Busy)
  413.               PutBox("That buffer is in use.","");
  414.             else {
  415.               // free the memory used by that buffer and coalesce the list
  416.               free(ImageBuffers[curBuff].DskSel);
  417.               free(ImageBuffers[curBuff].DskLayout);
  418.               while (((curBuff+1) < NUM_IMAGES) &&
  419.                      (ImageBuffers[curBuff].BufferName[0] != '\0')) {
  420.                 ImageBuffers[curBuff]  = ImageBuffers[curBuff+1];
  421.                 curBuff++;
  422.               }
  423.               WinDismissDlg(hwnd, TRUE);
  424.             }
  425.           }
  426.           else {
  427.             PutBox("You must select an existing","image buffer");
  428.           }
  429.           return(0);
  430.  
  431.         case DID_CANCEL:
  432.             WinDismissDlg(hwnd, FALSE);
  433.           return(0);
  434.       } // switch on commandID
  435.         break;
  436.     } // switch on msgID
  437.  
  438.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  439. } // DeleteDlgProc
  440.  
  441. VOID GetDirList(HWND hwnd, CHAR *pcCurrentPath)
  442. {
  443.  
  444. static CHAR szDrive [] = "  :" ;
  445. FILEFINDBUF3 findbuf ;
  446. HDIR         hDir = HDIR_SYSTEM;
  447. ULONG        attrs = MUST_HAVE_DIRECTORY | FILE_DIRECTORY;
  448. SHORT        sDrive ;
  449. ULONG        DriveNum;
  450. ULONG        CurPathLen;
  451. ULONG        SearchCount = 1 ;
  452. ULONG        ulDriveMap ;
  453. APIRET       rc;
  454.  
  455.   DosQCurDisk (&DriveNum, &ulDriveMap) ;
  456.   pcCurrentPath[0] = (CHAR) DriveNum + '@' ;
  457.   pcCurrentPath[1] = ':' ;
  458.   pcCurrentPath[2] = '\\' ;
  459.   CurPathLen = 64 ;
  460.   DosQCurDir(0, pcCurrentPath + 3, &CurPathLen) ;
  461.  
  462.   WinSetDlgItemText (hwnd, IDD_DI_PATH, pcCurrentPath) ;
  463.   WinSendDlgItemMsg (hwnd, IDD_DI_DIRS, LM_DELETEALL, NULL, NULL) ;
  464.  
  465.   for (sDrive = 0 ; sDrive < 26 ; sDrive++)
  466.     if (ulDriveMap & 1L << sDrive)
  467.     {
  468.       szDrive [1] = (CHAR) sDrive + 'A' ;
  469.  
  470.       WinSendDlgItemMsg(hwnd,
  471.                         IDD_DI_DIRS,
  472.                         LM_INSERTITEM,
  473.                         MPFROM2SHORT (LIT_END, 0),
  474.                         MPFROMP (szDrive)) ;
  475.     }
  476.  
  477.   rc = DosFindFirst("*.*",&hDir,attrs,&findbuf,sizeof findbuf,&SearchCount,1) ;
  478.   while (!rc)
  479.   {
  480.     if ((findbuf.attrFile & 0x0010) &&
  481.         (findbuf.achName [0] != '.' || findbuf.achName [1]))
  482.                
  483.     WinSendDlgItemMsg(hwnd, IDD_DI_DIRS, LM_INSERTITEM,
  484.                                   MPFROM2SHORT (LIT_SORTASCENDING, 0),
  485.                                   MPFROMP (findbuf.achName)) ;
  486.  
  487.     rc = DosFindNext(hDir, &findbuf, sizeof findbuf, &SearchCount) ;
  488.   }
  489.   return;
  490. } // GetDirList
  491.  
  492. VOID GetFileList(HWND hwnd)
  493. {
  494.  
  495. FILEFINDBUF3 findbuf ;
  496. HDIR         hDir = HDIR_SYSTEM ;
  497. ULONG        attrs = 0;
  498. ULONG        SearchCount = 1 ;
  499. APIRET       rc;
  500.  
  501.   WinSendDlgItemMsg (hwnd, IDD_DI_FILES, LM_DELETEALL, NULL, NULL) ;
  502.  
  503.   rc = DosFindFirst("*.*",&hDir,attrs,&findbuf,sizeof findbuf,&SearchCount,1);
  504.   while (!rc)
  505.   {
  506.     WinSendDlgItemMsg(hwnd,
  507.                       IDD_DI_FILES,
  508.                       LM_INSERTITEM,
  509.                       MPFROM2SHORT (LIT_SORTASCENDING, 0),
  510.                       MPFROMP (findbuf.achName)) ;
  511.  
  512.     rc = DosFindNext(hDir, &findbuf, sizeof findbuf, &SearchCount) ;
  513.   }
  514.   return;
  515. } // GetFileList
  516.  
  517.  
  518. //  In:    pcOut -- Pointer to parsed file spec
  519. //         pcIn  -- Pointer to raw file spec
  520. //  Returns 0 if bad file name
  521. //          1 if nothing
  522. //          else ok
  523. //
  524. //  Note:  Changes current drive and directory to pcIn
  525. //
  526. BOOL ParseFileName (CHAR *pcOut, CHAR *pcIn) {
  527.                        
  528. CHAR   *pcLastSlash;
  529. CHAR   *pcFileOnly;
  530. ULONG  ulDriveMap ;
  531. ULONG  DriveNum;
  532. ULONG  DirLen = 64;
  533.  
  534.   strupr(pcIn);
  535.   if (pcIn[0] == '\0') return(1);
  536.  
  537.   // Get drive from input string or current drive
  538.   if (pcIn[1] == ':') {
  539.     if (DosSelectDisk(pcIn[0] - '@')) return(0);
  540.     pcIn += 2 ;
  541.   }
  542.   DosQCurDisk(&DriveNum, &ulDriveMap) ;
  543.  
  544.   *pcOut++ = (CHAR) DriveNum + '@' ;
  545.   *pcOut++ = ':' ;
  546.   *pcOut++ = '\\' ;
  547.  
  548.   // If rest of string is empty, return error
  549.   if (pcIn[0] == '\0') return(1);
  550.  
  551.   // Search for last backslash.  If none, could be directory.
  552.   if (NULL == (pcLastSlash = strrchr(pcIn, '\\')))
  553.   {
  554.     if (!DosChDir(pcIn)) return(1);
  555.  
  556.     // Otherwise, get current dir & attach input filename
  557.     DosQCurDir(0, pcOut, &DirLen);
  558.     if (*(pcOut + strlen(pcOut) - 1) != '\\') strcat(pcOut++, "\\");
  559.     strcat(pcOut, pcIn) ;
  560.     return(2);
  561.   }
  562.   // If the only backslash is at beginning, change to root
  563.   if (pcIn == pcLastSlash)
  564.   {
  565.     DosChDir("\\") ;
  566.     if (pcIn[1] == '\0') return(1);
  567.     strcpy(pcOut, pcIn + 1);
  568.     return(2);
  569.   }
  570.  
  571.   // Attempt to change directory -- Get current dir if OK
  572.   *pcLastSlash = '\0';
  573.   if (DosChDir(pcIn)) return(0);
  574.   DosQCurDir(0, pcOut, &DirLen);
  575.  
  576.   // Append input filename, if any
  577.   pcFileOnly = pcLastSlash + 1;
  578.   if (*pcFileOnly == '\0') return(1);
  579.   if (*(pcOut + strlen(pcOut) - 1) != '\\') strcat(pcOut++, "\\");
  580.   strcat(pcOut, pcFileOnly);
  581.   return(2);
  582. } // ParseFileName
  583.  
  584.  
  585. //  return true if everything is okay
  586. BOOL CheckLSParms(HWND hwnd, USHORT Mode) {
  587.  
  588. CHAR   szBuffer[FILENMSZ];
  589. USHORT curBuff;
  590. CHAR   curBuffName[BUFFERNMSZ];
  591. USHORT NameLen;
  592. USHORT curChar;
  593. CHAR   szFileName[FILENMSZ];
  594.  
  595.   NameLen = WinQueryDlgItemText(hwnd,
  596.                                 IDD_DI_FNAME,
  597.                                 FILENMSZ,
  598.                                 szBuffer);
  599.  
  600.   switch (ParseFileName(szFileName, szBuffer)) {
  601.     case 0:
  602.       PutBox("Illegal file name.","");
  603.       return(FALSE);
  604.     case 1: // no error, just don't do anything
  605.       return(FALSE);
  606.   }
  607.   NameLen = WinQueryDlgItemText(hwnd,
  608.                                 IDD_DI_FLD,
  609.                                 BUFFERNMSZ,
  610.                                 curBuffName);
  611.  
  612.   if (NameLen == 0) {
  613.     PutBox("You must enter a buffer name,","or select 'Cancel'");
  614.     return(FALSE);
  615.   }
  616.  
  617.   for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  618.     curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  619.  
  620. // set the current buffer - must base on mode 'cause save can only use
  621. // existing buffers while load can create new ones
  622.   if (Mode == BUSY_LOAD)
  623.     for (curBuff=0;
  624.          (curBuff < NUM_IMAGES) &&
  625.          (ImageBuffers[curBuff].BufferName[0] != '\0') &&
  626.          (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  627.          curBuff++);
  628.   else
  629.     for (curBuff=0;
  630.          (curBuff < NUM_IMAGES) &&
  631.          (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  632.          curBuff++);
  633.  
  634.  
  635.   if (NameLen < 1) {
  636.     PutBox("You must select an","image buffer");
  637.     return(FALSE);
  638.   }
  639.  
  640.   if (curBuff < NUM_IMAGES) {
  641.     if (ImageBuffers[curBuff].Busy)
  642.       PutBox("That buffer is in use.","");
  643.     else {
  644.       strcpy(ImageBuffers[curBuff].FileName,szFileName);
  645.       strncpy(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ);
  646.       ImageBuffers[curBuff].DriveID[0] = ' ';
  647.       ImageBuffers[curBuff].Busy = Mode;
  648.       BufferNum = curBuff;
  649.       return(TRUE);
  650.     }
  651.   }
  652.   else
  653.     PutBox("You must select an existing","image buffer");
  654.   return(FALSE);
  655. } // CheckLSParms
  656.  
  657.  
  658. //  LoadDlgProc  --  Image Buffer Load dialog procedure.
  659. //
  660. MRESULT LoadDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  661. {
  662.  
  663. USHORT curBuff;
  664. static CHAR szCurrentPath[FILENMSZ];
  665. static CHAR szBuffer[FILENMSZ];
  666. SHORT  Select;
  667.  
  668.   switch (id)
  669.     {
  670.     case WM_INITDLG:
  671.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  672.       GetDirList(hwnd, szCurrentPath) ;
  673.       GetFileList(hwnd) ;
  674.  
  675.       WinSendDlgItemMsg(hwnd,
  676.                         IDD_DI_FNAME,
  677.                         EM_SETTEXTLIMIT,
  678.                         MPFROM2SHORT (FILENMSZ, 0),
  679.                         NULL) ;
  680.       WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,IDD_DI_FNAME));
  681.       return(0);
  682.  
  683.     case WM_CONTROL:  // get the button that was clicked
  684.       switch (SHORT1FROMMP(mp1)) {
  685.         case IDD_DI_DIRS:
  686.           Select = (USHORT) WinSendDlgItemMsg(hwnd,
  687.                                               SHORT1FROMMP(mp1),
  688.                                               LM_QUERYSELECTION,
  689.                                               0L,
  690.                                               0L) ;
  691.  
  692.           WinSendDlgItemMsg(hwnd,
  693.                             SHORT1FROMMP(mp1),
  694.                             LM_QUERYITEMTEXT,
  695.                             MPFROM2SHORT(Select, sizeof szBuffer),
  696.                             MPFROMP(szBuffer)) ;
  697.           switch (SHORT2FROMMP(mp1)) {
  698.             case LN_ENTER:
  699.               if (szBuffer[0] == ' ') DosSelectDisk(szBuffer[1] - '@');
  700.               else DosChDir (szBuffer);
  701.  
  702.               GetDirList(hwnd, szCurrentPath);
  703.               GetFileList(hwnd);
  704.  
  705.               WinSetDlgItemText(hwnd, IDD_DI_FNAME, "");
  706.               return(0);
  707.           }
  708.           break;
  709.  
  710.         case IDD_DI_FILES:
  711.           Select = (USHORT) WinSendDlgItemMsg(hwnd,
  712.                                               SHORT1FROMMP(mp1),
  713.                                               LM_QUERYSELECTION,
  714.                                               0L,
  715.                                               0L) ;
  716.  
  717.           WinSendDlgItemMsg(hwnd,
  718.                             SHORT1FROMMP(mp1),
  719.                             LM_QUERYITEMTEXT,
  720.                             MPFROM2SHORT(Select, sizeof szBuffer),
  721.                             MPFROMP(szBuffer)) ;
  722.           switch (SHORT2FROMMP(mp1)) {
  723.             case LN_SELECT:
  724.               WinSetDlgItemText(hwnd, IDD_DI_FNAME, szBuffer);
  725.               return(0);
  726.  
  727.             case LN_ENTER:
  728.               if (CheckLSParms(hwnd, BUSY_LOAD)) {
  729.                 WinDismissDlg(hwnd, TRUE);
  730.               }
  731.               return(0);
  732.           }
  733.           break ;
  734.  
  735.         case IDD_DI_BOX:
  736.           curBuff = SetBox(hwnd, mp1);
  737.           switch (SHORT2FROMMP(mp1)) {
  738.             case LN_SELECT:
  739.               WinSetDlgItemText(hwnd,
  740.                                 IDD_DI_FLD,
  741.                                 ImageBuffers[curBuff].BufferName);
  742.               return(0);
  743.             case LN_ENTER:
  744.               if (ImageBuffers[curBuff].Busy)
  745.                 PutBox("That buffer is in use.","");
  746.               else {
  747.                 if (CheckLSParms(hwnd, BUSY_LOAD)) {
  748.                   WinDismissDlg(hwnd, TRUE);
  749.                 }
  750.               }
  751.           }
  752.       }
  753.       return(0);
  754.  
  755.     case WM_COMMAND:
  756.       switch (COMMANDMSG(&id)->cmd)
  757.           {
  758.           case DID_OK:
  759.           if (CheckLSParms(hwnd, BUSY_LOAD)) {
  760.             WinDismissDlg(hwnd, TRUE);
  761.           }
  762.           return(0);
  763.  
  764.         case DID_CANCEL:
  765.           WinDismissDlg(hwnd, FALSE);
  766.           return(0);
  767.       } // switch on commandID
  768.         break;
  769.     } // switch on msgID
  770.  
  771.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  772. } // LoadDlgProc
  773.  
  774.  
  775. //  SaveDlgProc  --  Image Buffer Save dialog procedure.
  776. //
  777. MRESULT SaveDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  778. {
  779.  
  780. USHORT curBuff;
  781. static CHAR szCurrentPath [FILENMSZ];
  782. static CHAR szBuffer [FILENMSZ];
  783. SHORT  Select;
  784.  
  785.   switch (id)
  786.     {
  787.     case WM_INITDLG:
  788.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  789.       GetDirList(hwnd, szCurrentPath) ;
  790.       GetFileList(hwnd) ;
  791.  
  792.       WinSendDlgItemMsg(hwnd,
  793.                         IDD_DI_FNAME,
  794.                         EM_SETTEXTLIMIT,
  795.                         MPFROM2SHORT (FILENMSZ, 0),
  796.                         NULL) ;
  797.       return(0);
  798.  
  799.     case WM_CONTROL:  // get the button that was clicked
  800.       switch (SHORT1FROMMP(mp1)) {
  801.         case IDD_DI_DIRS:
  802.           Select = (USHORT) WinSendDlgItemMsg(hwnd,
  803.                                               SHORT1FROMMP(mp1),
  804.                                               LM_QUERYSELECTION,
  805.                                               0L,
  806.                                               0L) ;
  807.  
  808.           WinSendDlgItemMsg(hwnd,
  809.                             SHORT1FROMMP(mp1),
  810.                             LM_QUERYITEMTEXT,
  811.                             MPFROM2SHORT(Select, sizeof szBuffer),
  812.                             MPFROMP(szBuffer)) ;
  813.           switch (SHORT2FROMMP(mp1)) {
  814.             case LN_ENTER:
  815.               if (szBuffer[0] == ' ') DosSelectDisk(szBuffer[1] - '@');
  816.               else DosChDir (szBuffer);
  817.  
  818.               GetDirList(hwnd, szCurrentPath);
  819.               GetFileList(hwnd);
  820.  
  821.               WinSetDlgItemText(hwnd, IDD_DI_FNAME, "");
  822.               return(0);
  823.           }
  824.           break;
  825.  
  826.         case IDD_DI_FILES:
  827.           Select = (USHORT) WinSendDlgItemMsg(hwnd,
  828.                                               SHORT1FROMMP(mp1),
  829.                                               LM_QUERYSELECTION,
  830.                                               0L,
  831.                                               0L) ;
  832.  
  833.           WinSendDlgItemMsg(hwnd,
  834.                             SHORT1FROMMP(mp1),
  835.                             LM_QUERYITEMTEXT,
  836.                             MPFROM2SHORT(Select, sizeof szBuffer),
  837.                             MPFROMP(szBuffer)) ;
  838.           switch (SHORT2FROMMP(mp1)) {
  839.             case LN_SELECT:
  840.               WinSetDlgItemText(hwnd, IDD_DI_FNAME, szBuffer);
  841.               return(0);
  842.  
  843.             case LN_ENTER:
  844.               if (CheckLSParms(hwnd, BUSY_SAVE)) {
  845.                 WinDismissDlg(hwnd, TRUE);
  846.               }
  847.               return(0);
  848.           }
  849.           break ;
  850.  
  851.         case IDD_DI_BOX:
  852.           curBuff = SetBox(hwnd, mp1);
  853.           switch (SHORT2FROMMP(mp1)) {
  854.             case LN_SELECT:
  855.               WinSetDlgItemText(hwnd,
  856.                                 IDD_DI_FLD,
  857.                                 ImageBuffers[curBuff].BufferName);
  858.               return(0);
  859.             case LN_ENTER:
  860.               if (ImageBuffers[curBuff].Busy)
  861.                 PutBox("That buffer is in use.","");
  862.               else {
  863.                 if (CheckLSParms(hwnd, BUSY_SAVE)) {
  864.                   WinDismissDlg(hwnd, TRUE);
  865.                 }
  866.               }
  867.           }
  868.       } // switch for CONTROL
  869.         return(0);
  870.  
  871.     case WM_COMMAND:
  872.       switch (COMMANDMSG(&id)->cmd)
  873.           {
  874.           case DID_OK:
  875.           if (CheckLSParms(hwnd, BUSY_SAVE)) {
  876.             WinDismissDlg(hwnd, TRUE);
  877.           }
  878.           return(0);
  879.  
  880.         case DID_CANCEL:
  881.             WinDismissDlg(hwnd, FALSE);
  882.           return(0);
  883.       } // switch on commandID
  884.         break;
  885.     } // switch on msgID
  886.  
  887.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  888. } // SaveDlgProc
  889.  
  890.  
  891.  
  892. //
  893. // return the buffer number of the field in the edit box
  894. //
  895. USHORT SetEdit(HWND hwnd, USHORT EditB) {
  896.  
  897. USHORT curBuff;
  898. USHORT curChar;
  899. CHAR   curBuffName[BUFFERNMSZ];
  900. USHORT NameLen;
  901.  
  902.   NameLen = WinQueryDlgItemText(hwnd,
  903.                                 EditB,
  904.                                 BUFFERNMSZ,
  905.                                 curBuffName);
  906.  
  907.   if (NameLen == 0) {
  908.     PutBox("You must enter an image name,","  or select 'Cancel'");
  909.     return(NUM_IMAGES+1);
  910.   }
  911.  
  912.   for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  913.     curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  914.  
  915.   for (curBuff=0;
  916.        (curBuff < NUM_IMAGES) &&
  917.        (ImageBuffers[curBuff].BufferName[0] != '\0') &&
  918.        (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  919.        curBuff++) ;
  920.  
  921.   if (curBuff == NUM_IMAGES) {
  922.     PutBox("You must select an existing","image buffer");
  923.     return(NUM_IMAGES+1);
  924.   }
  925.  
  926.   if (ImageBuffers[curBuff].Busy) {
  927.     PutBox("The image is busy -","please select another");
  928.     return(NUM_IMAGES+1);
  929.   }
  930.  
  931.   return(curBuff);
  932. }
  933.  
  934. //  CompDlgProc  --  Image Buffer Compare dialog procedure.
  935. //
  936. MRESULT CompDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  937. {
  938.  
  939. USHORT curBuff;
  940.  
  941.   switch (id)
  942.     {
  943.     case WM_INITDLG:
  944.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  945.       GetImageList(hwnd, IDD_CM_FLD, IDD_CM_BOX);
  946.       BufferNum = NUM_IMAGES+1;
  947.       CompNum = NUM_IMAGES+1;
  948.       return(0);
  949.  
  950.     case WM_CONTROL:  // get the button that was clicked
  951.       curBuff = SetBox(hwnd, mp1);
  952.       switch (SHORT1FROMMP(mp1)) {
  953.  
  954.         case IDD_DI_BOX:
  955.           switch (SHORT2FROMMP(mp1)) {
  956.             case LN_SELECT:
  957.               WinSetDlgItemText(hwnd,
  958.                                 IDD_DI_FLD,
  959.                                 ImageBuffers[curBuff].BufferName);
  960.               return(0);
  961.             case LN_ENTER:
  962.               BufferNum = SetEdit(hwnd, IDD_DI_FLD);
  963.               CompNum   = SetEdit(hwnd, IDD_CM_FLD);
  964.               if ((CompNum == (NUM_IMAGES+1)) ||
  965.                   (CompNum == BufferNum))
  966.                 PutBox("You must select two","different (and existing) images");
  967.               else {
  968.                 ImageBuffers[BufferNum].Busy = BUSY_COMP;
  969.                 ImageBuffers[CompNum].Busy = BUSY_COMP;
  970.                 WinDismissDlg(hwnd, TRUE);
  971.               }
  972.           }
  973.           break;
  974.         case IDD_CM_BOX:
  975.           switch (SHORT2FROMMP(mp1)) {
  976.             case LN_SELECT:
  977.               WinSetDlgItemText(hwnd,
  978.                                 IDD_CM_FLD,
  979.                                 ImageBuffers[curBuff].BufferName);
  980.               CompNum = curBuff;
  981.               return(0);
  982.             case LN_ENTER:
  983.               BufferNum = SetEdit(hwnd, IDD_DI_FLD);
  984.               CompNum   = SetEdit(hwnd, IDD_CM_FLD);
  985.               if ((BufferNum == (NUM_IMAGES+1)) ||
  986.                   (BufferNum == CompNum))
  987.                 PutBox("You must select two","different (and existing) images");
  988.               else {
  989.                 ImageBuffers[BufferNum].Busy = BUSY_COMP;
  990.                 ImageBuffers[CompNum].Busy = BUSY_COMP;
  991.                 WinDismissDlg(hwnd, TRUE);
  992.               }
  993.           }
  994.           break;
  995.       } // switch for CONTROL
  996.         return(0);
  997.  
  998.     case WM_COMMAND:
  999.       switch (COMMANDMSG(&id)->cmd)
  1000.           {
  1001.           case DID_OK:
  1002.           BufferNum = SetEdit(hwnd, IDD_DI_FLD);
  1003.           CompNum   = SetEdit(hwnd, IDD_CM_FLD);
  1004.           ImageBuffers[BufferNum].Busy = BUSY_COMP;
  1005.           ImageBuffers[CompNum].Busy = BUSY_COMP;
  1006.           WinDismissDlg(hwnd, TRUE);
  1007.           return(0);
  1008.  
  1009.         case DID_CANCEL:
  1010.             WinDismissDlg(hwnd, FALSE);
  1011.           return(0);
  1012.       } // switch on commandID
  1013.         break;
  1014.     } // switch on msgID
  1015.  
  1016.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  1017. } // CompDlgProc
  1018.  
  1019.  
  1020. //  AboutDlgProc  --  About box dialog procedure.
  1021. //
  1022. MRESULT AboutDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  1023. {
  1024.  
  1025.   switch (id)
  1026.   {
  1027.     case WM_COMMAND:
  1028.       switch (COMMANDMSG(&id)->cmd)
  1029.           {
  1030.           case DID_OK:
  1031.         case DID_CANCEL:
  1032.             WinDismissDlg(hwnd, TRUE);
  1033.           return 0;
  1034.       } // switch on commandID
  1035.         break;
  1036.     } // switch on msgID
  1037.  
  1038.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  1039. } // AboutDlgProc
  1040.