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

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