home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / pmflp301.zip / diskcopy / copyDlgs.c < prev    next >
C/C++ Source or Header  |  1997-01-08  |  37KB  |  1,333 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. #define INCL_DOSDEVIOCTL
  24. #define INCL_DOSFILEMGR
  25. #include <os2.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include "pmfloppy.h"
  30. #include "DskIm.h"
  31. #include "funcdefs.h"
  32.  
  33. /* external function prototypes */
  34. extern VOID   PutBox(PSZ, PSZ);
  35.  
  36.  
  37. /* global function prototypes */
  38. #if 0
  39. MRESULT WriteDlgProc(HWND, USHORT, MPARAM, MPARAM);
  40. MRESULT DeleteDlgProc(HWND, USHORT, MPARAM, MPARAM);
  41. MRESULT LoadDlgProc(HWND, USHORT, MPARAM, MPARAM);
  42. MRESULT SaveDlgProc(HWND, USHORT, MPARAM, MPARAM);
  43. MRESULT CompDlgProc(HWND, USHORT, MPARAM, MPARAM);
  44. MRESULT AboutDlgProc(HWND, USHORT, MPARAM, MPARAM);
  45. #endif
  46.  
  47. /* local function prototypes */
  48. VOID   GetImageList(HWND, USHORT, USHORT);
  49. VOID   GetDirList(HWND, CHAR *);
  50. VOID   GetFileList(HWND);
  51. USHORT SetBox(HWND, MPARAM);
  52. USHORT SetEdit(HWND, USHORT);
  53. BOOL   SetDrive(HWND, USHORT);
  54. BOOL   ParseFileName (CHAR *, CHAR *);
  55. BOOL   CheckLSParms(HWND, USHORT);
  56.  
  57. /* PM vbls */
  58. extern HWND   hWndFrame ;
  59.  
  60. /* User response vbls */
  61. extern DskImage ImageBuffers[NUM_IMAGES];
  62. extern USHORT    BufferNum;
  63. extern USHORT    CompNum;
  64. extern char    imageFileName[260];
  65.  
  66. static char DiskName[2] = {'A', '\0'};
  67. static int        secondUsed;
  68.  
  69. /* ********************************** GetImageList ********************** */
  70. /* set up image list and edit boxes */
  71. /* Modified 7/94 (ROB) so that image buffers do not have to be contiguous */
  72. static VOID GetImageList(HWND hwnd, USHORT EditB, USHORT ListB) {
  73.  
  74. USHORT curBuff;
  75. int        firstUsed = 0;
  76.  
  77. secondUsed = 0;
  78.   for (curBuff=0;  (curBuff < NUM_IMAGES);  curBuff++) {
  79.     if (ImageBuffers[curBuff].BufferName[0] != '\0')
  80.         {if (!firstUsed)
  81.             firstUsed = curBuff + 1;
  82.         else if(!secondUsed)
  83.             secondUsed = curBuff;
  84.         WinSendDlgItemMsg(hwnd,
  85.               ListB,
  86.               LM_INSERTITEM,
  87.               MPFROM2SHORT(LIT_END,0),
  88.               MPFROMP(ImageBuffers[curBuff].BufferName));
  89.         }
  90.   }
  91.   curBuff = 0;
  92. if (EditB)
  93.     WinSendDlgItemMsg(hwnd,
  94.             EditB,
  95.             EM_SETTEXTLIMIT,
  96.             MPFROM2SHORT(BUFFERNMSZ,0),
  97.             NULL);
  98.  
  99. if (firstUsed && EditB)
  100.   WinSetDlgItemText(hwnd, EditB, ImageBuffers[firstUsed-1].BufferName);
  101.   return;
  102. } /* GetImageList */
  103. /* ***************************** getImageNum ***************************** */
  104. /* return the buffer number of the selected image */
  105. static USHORT getImageNum(HWND hwnd, int windowID) {
  106.  
  107. USHORT curBuff;
  108. MRESULT  Select;
  109. CHAR    curBuffName[BUFFERNMSZ],
  110.         *pch;
  111. int        i,
  112.         unused = -1;
  113.  
  114. /* get the selection text */
  115. WinQueryDlgItemText (hwnd, windowID, BUFFERNMSZ, curBuffName);
  116. for (pch=curBuffName, i=0;    i<BUFFERNMSZ;    ++i, ++pch)
  117.     *pch = toupper (*pch);
  118. /* get the buffer number*/
  119. for (curBuff=0;
  120.      (curBuff < NUM_IMAGES) &&
  121.      (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  122.      curBuff++)
  123.     {if (unused == -1)
  124.         if(!ImageBuffers[curBuff].BufferName[0])
  125.             unused = curBuff;
  126.     }
  127. if(unused != -1)
  128.     {strcpy (ImageBuffers[unused].BufferName, curBuffName);
  129.     return unused;
  130.     }
  131. return(curBuff);
  132. }
  133.  
  134. /* ******************************* SetBox ******************************* */
  135. /* return the buffer number of the selected image */
  136. static USHORT SetBox(HWND hwnd, MPARAM mp1) {
  137.  
  138. USHORT curBuff;
  139. MRESULT  Select;
  140. CHAR   curBuffName[BUFFERNMSZ];
  141. int        unused = -1;
  142.  
  143.   /* get the selection number */
  144.   Select =         WinSendDlgItemMsg(hwnd,
  145.                        SHORT1FROMMP(mp1),
  146.                       LM_QUERYSELECTION,
  147.                       0L,
  148.                       0L);
  149.   /* get the selection text */
  150.   WinSendDlgItemMsg(hwnd,
  151.             SHORT1FROMMP(mp1),
  152.             LM_QUERYITEMTEXT,
  153.             MPFROM2SHORT(Select,BUFFERNMSZ),
  154.             MPFROMP(curBuffName));
  155.   /* get the buffer number*/
  156.   for (curBuff=0;
  157.        (curBuff < NUM_IMAGES) &&
  158.        (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  159.        curBuff++)
  160.     {if (unused == -1)
  161.         if(!ImageBuffers[curBuff].diskBuffer)
  162.             unused = curBuff;
  163.     
  164.     }
  165. if(unused != -1)
  166.     return unused;
  167.   return(curBuff);
  168. } /* SetBox */
  169.  
  170. /* ******************************** SetDrive ***************************** */
  171. /* Set the drive letter - returns true if illegal value */
  172. static BOOL SetDrive(HWND hwnd, USHORT curBuff) {
  173.  
  174.   WinQueryDlgItemText(hwnd,
  175.               IDD_DI_DRV,
  176.               2,
  177.               ImageBuffers[curBuff].DriveID);
  178.   ImageBuffers[curBuff].DriveID[0] = (CHAR) toupper(ImageBuffers[curBuff].DriveID[0]);
  179.   if (!isupper((USHORT) ImageBuffers[curBuff].DriveID[0])) {
  180.     PutBox("Destination Drive must be a drive letter","e.g. A");
  181.     return(TRUE);
  182.   }
  183. DiskName[0] = ImageBuffers[curBuff].DriveID[0];
  184.   return(FALSE);
  185. } /* SetDrive */
  186.  
  187.  
  188. /* *************************** ReadDlgProc ****************************** */
  189. /*  ReadDlgProc  --  Disk Read dialog procedure. */
  190. /*  Output:  ReadDrive    --  Global name of selected drive */
  191. MRESULT EXPENTRY ReadDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2) {
  192.  
  193. USHORT curChar;
  194. USHORT curBuff;
  195. CHAR   curBuffName[BUFFERNMSZ];
  196. USHORT NameLen;
  197.  
  198.   switch (id)    {
  199.     case WM_INITDLG:
  200.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  201.       WinSendDlgItemMsg(hwnd,
  202.             IDD_DI_DRV,
  203.             EM_SETTEXTLIMIT,
  204.             MPFROM2SHORT(1,0),
  205.             NULL);
  206.     WinSetWindowText (WinWindowFromID ( hwnd, IDD_DI_DRV), DiskName);
  207.       return(0);
  208.  
  209.     case WM_CONTROL:  /* get the button that was clicked */
  210.       if (SHORT1FROMMP(mp1) == IDD_DI_BOX) {
  211.     curBuff = SetBox(hwnd, mp1);
  212.     switch (SHORT2FROMMP(mp1)) {
  213.       case LN_SELECT:
  214.         WinSetDlgItemText(hwnd,
  215.                   IDD_DI_FLD,
  216.                   ImageBuffers[curBuff].BufferName);
  217.         return(0);
  218.       case LN_ENTER:
  219.         if (SetDrive(hwnd, curBuff)) return(0);
  220.         if (ImageBuffers[curBuff].Busy) {
  221.           PutBox("That image is busy -","please select another");
  222.         }
  223.         else {
  224.           ImageBuffers[curBuff].Busy = BUSY_READ;
  225.           BufferNum = curBuff;
  226.           WinDismissDlg(hwnd, TRUE);
  227.         }
  228.         return(0);
  229.     }
  230.  
  231.       }
  232.         return(0);
  233.  
  234.     case WM_COMMAND:
  235.       switch (COMMANDMSG(&id)->cmd)
  236.           {
  237.           case DID_OK:
  238.       NameLen = WinQueryDlgItemText(hwnd,
  239.                     IDD_DI_FLD,
  240.                     BUFFERNMSZ,
  241.                     curBuffName);
  242.  
  243.       if (NameLen == 0) {
  244.         PutBox("You must enter a buffer name,","or select 'Cancel'");
  245.         return(0);
  246.       }
  247.  
  248.       for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  249.         curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  250.  
  251.       for (curBuff=0;
  252.            (curBuff < NUM_IMAGES) &&
  253.            (ImageBuffers[curBuff].BufferName[0] != '\0') &&
  254.            (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  255.            curBuff++) ;
  256.  
  257.       if (curBuff < NUM_IMAGES) {
  258.         if (SetDrive(hwnd, curBuff)) return(0);
  259.         if (ImageBuffers[curBuff].Busy) {
  260.           PutBox("That image is busy -","please select another");
  261.         }
  262.         else {
  263.           ImageBuffers[curBuff].Busy = BUSY_READ;
  264.           strncpy(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ);
  265.           BufferNum = curBuff;
  266.           WinDismissDlg(hwnd, TRUE);
  267.         }
  268.  
  269.       }
  270.       else {
  271.         PutBox("No image buffers left","(try deleting some)");
  272.       }
  273.       return(0);
  274.  
  275.  
  276.     case DID_CANCEL:
  277.          WinDismissDlg(hwnd, FALSE);
  278.       return(0);
  279.       } /* switch on commandID */
  280.         break;
  281.     } /* switch on msgID */
  282.  
  283.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  284. } /* ReadDlgProc */
  285.  
  286. /* **************************** WriteDlgProc ****************************** */
  287. /*  WriteDlgProc  --  Disk Write dialog procedure. */
  288. /*  Output:  WriteDrive  --  Global name of selected drive */
  289. MRESULT EXPENTRY WriteDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2) {
  290.  
  291. USHORT NameLen;
  292. USHORT curChar;
  293. USHORT curBuff;
  294. static CHAR   curBuffName[BUFFERNMSZ];
  295. static USHORT FormOpt;
  296.  
  297.   switch (id)
  298.     {
  299.     case WM_INITDLG:
  300.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  301.       WinSendDlgItemMsg(hwnd,
  302.             IDD_DI_DRV,
  303.             EM_SETTEXTLIMIT,
  304.             MPFROM2SHORT(1,0),
  305.             NULL);
  306.     WinSetWindowText (WinWindowFromID ( hwnd, IDD_DI_DRV), DiskName);
  307.       WinSendDlgItemMsg(hwnd,
  308.             IDD_WRF_MAYBE,
  309.             BM_SETCHECK,
  310.             MPFROMSHORT(1),
  311.             NULL);
  312.       FormOpt = IDD_WRF_MAYBE;
  313.       return(0);
  314.  
  315.     case WM_CONTROL:  /* get the button that was clicked*/
  316.       if (SHORT1FROMMP(mp1) == IDD_DI_BOX) {
  317.     curBuff = SetBox(hwnd, mp1);
  318.     switch (SHORT2FROMMP(mp1)) {
  319.       case LN_SELECT:
  320.         WinSetDlgItemText(hwnd,
  321.                   IDD_DI_FLD,
  322.                   ImageBuffers[curBuff].BufferName);
  323.         return(0);
  324.       case LN_ENTER:
  325.         if (SetDrive(hwnd, curBuff)) return(0);
  326.         if (ImageBuffers[curBuff].Busy) {
  327.           PutBox("That image is busy -","please select another");
  328.         }
  329.         else {
  330.           ImageBuffers[curBuff].Busy = BUSY_WRITE;
  331.           ImageBuffers[curBuff].FormatOptions = FormOpt;
  332.           BufferNum = curBuff;
  333.           WinDismissDlg(hwnd, TRUE);
  334.         }
  335.         return(0);
  336.     }
  337.  
  338.       }
  339.       else if ((SHORT1FROMMP(mp1) == IDD_WRF_NEVER) ||
  340.            (SHORT1FROMMP(mp1) == IDD_WRF_MAYBE) ||
  341.            (SHORT1FROMMP(mp1) == IDD_WRF_ALWAYS))
  342.     FormOpt = SHORT1FROMMP(mp1);
  343.         return(0);
  344.  
  345.     case WM_COMMAND:
  346.       switch (COMMANDMSG(&id)->cmd)
  347.           {
  348.           case DID_OK:
  349.       NameLen = WinQueryDlgItemText(hwnd,
  350.                     IDD_DI_FLD,
  351.                     BUFFERNMSZ,
  352.                     curBuffName);
  353.  
  354.       for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  355.         curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  356.  
  357.       for (curBuff=0;
  358.            (curBuff < NUM_IMAGES) &&
  359.            (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  360.            curBuff++) ;
  361.  
  362.       if ((curBuff < NUM_IMAGES) && (NameLen > 0)) {
  363.         if (SetDrive(hwnd, curBuff)) return(0);
  364.         if (ImageBuffers[curBuff].Busy) {
  365.           PutBox("That image is busy -","please select another");
  366.         }
  367.         else {
  368.           ImageBuffers[curBuff].Busy = BUSY_WRITE;
  369.           strncpy(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ);
  370.           ImageBuffers[curBuff].FormatOptions = FormOpt;
  371.           BufferNum = curBuff;
  372.           WinDismissDlg(hwnd, TRUE);
  373.         }
  374.       }
  375.       else {
  376.         PutBox("You must select an existing","image buffer");
  377.  
  378.       }
  379.       return(0);
  380.  
  381.     case DID_CANCEL:
  382.          WinDismissDlg(hwnd, FALSE);
  383.       return(0);
  384.       } /* switch on commandID*/
  385.         break;
  386.     } /* switch on msgID*/
  387.  
  388.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  389. } /* WriteDlgProc*/
  390.  
  391.  
  392. /* ********************************* DeleteDlgProc ************************* */
  393. /*  DeleteDlgProc  --  Image Buffer Delete dialog procedure.*/
  394. /**/
  395. MRESULT EXPENTRY DeleteDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2) {
  396.  
  397. USHORT NameLen;
  398. USHORT curChar;
  399. USHORT curBuff;
  400. CHAR   curBuffName[BUFFERNMSZ];
  401.  
  402.   switch (id)
  403.     {
  404.     case WM_INITDLG:
  405.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  406.       return(0);
  407.  
  408.     case WM_CONTROL:  /* get the button that was clicked*/
  409.       if (SHORT1FROMMP(mp1) == IDD_DI_BOX) {
  410.     curBuff = SetBox(hwnd, mp1);
  411.     switch (SHORT2FROMMP(mp1)) {
  412.       case LN_SELECT:
  413.         WinSetDlgItemText(hwnd,
  414.                   IDD_DI_FLD,
  415.                   ImageBuffers[curBuff].BufferName);
  416.         return(0);
  417.       case LN_ENTER:
  418.         if (ImageBuffers[curBuff].Busy)
  419.           PutBox("That buffer is in use.","");
  420.         else {
  421.           /* free the memory used by that buffer and coalesce the list*/
  422.                 DosFreeMem (ImageBuffers[curBuff].diskBuffer);
  423.                 ImageBuffers[curBuff].diskBuffer = NULL;
  424.                 ImageBuffers[curBuff].BufferName[0] = '\0';
  425.           free(ImageBuffers[curBuff].DskLayout);
  426.                 ImageBuffers[curBuff].volumeLabel[0] = '\0';
  427.           WinDismissDlg(hwnd, TRUE);
  428.         }
  429.     }
  430.  
  431.       }
  432.         return(0);
  433.  
  434.     case WM_COMMAND:
  435.       switch (COMMANDMSG(&id)->cmd)
  436.           {
  437.           case DID_OK:
  438.       NameLen = WinQueryDlgItemText(hwnd,
  439.                     IDD_DI_FLD,
  440.                     BUFFERNMSZ,
  441.                     curBuffName);
  442.  
  443.       for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  444.         curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  445.  
  446.       for (curBuff=0;
  447.            (curBuff < NUM_IMAGES) &&
  448.            (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  449.            curBuff++) ;
  450.  
  451.       if ((curBuff < NUM_IMAGES) && (NameLen > 0)) {
  452.         if (ImageBuffers[curBuff].Busy)
  453.           PutBox("That buffer is in use.","");
  454.         else {
  455.           /* free the memory used by that buffer and coalesce the list*/
  456.                 DosFreeMem (ImageBuffers[curBuff].diskBuffer);
  457.                 ImageBuffers[curBuff].diskBuffer = NULL;
  458.           free(ImageBuffers[curBuff].DskLayout);
  459.                 ImageBuffers[curBuff].BufferName[0] = '\0';
  460.                 ImageBuffers[curBuff].volumeLabel[0] = '\0';
  461.           WinDismissDlg(hwnd, TRUE);
  462.         }
  463.       }
  464.       else {
  465.         PutBox("You must select an existing","image buffer");
  466.       }
  467.       return(0);
  468.  
  469.     case DID_CANCEL:
  470.          WinDismissDlg(hwnd, FALSE);
  471.       return(0);
  472.       } /* switch on commandID*/
  473.         break;
  474.     } /* switch on msgID*/
  475.  
  476.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  477. } /* DeleteDlgProc*/
  478.  
  479. /* ******************************* GetDirList ***************************** */
  480. VOID GetDirList(HWND hwnd, CHAR *pcCurrentPath) {
  481.  
  482. static CHAR szDrive [] = "  :" ;
  483. FILEFINDBUF3 findbuf ;
  484. HDIR        hDir = HDIR_CREATE;
  485. SHORT        sDrive ;
  486. ULONG       usDriveNum, usCurPathLen, usSearchCount = 1 ;
  487. ULONG        ulDriveMap ;
  488. APIRET         rc;
  489. ULONG        searchMask;
  490.  
  491.   DosQCurDisk (&usDriveNum, &ulDriveMap) ;
  492.   pcCurrentPath[0] = (CHAR) usDriveNum + '@' ;
  493.   pcCurrentPath[1] = ':' ;
  494.   pcCurrentPath[2] = '\\' ;
  495.   usCurPathLen = 64 ;
  496.   DosQCurDir(0, pcCurrentPath + 3, &usCurPathLen) ;
  497.  
  498.   WinSetDlgItemText (hwnd, IDD_DI_PATH, pcCurrentPath) ;
  499.   WinSendDlgItemMsg (hwnd, IDD_DI_DIRS, LM_DELETEALL, NULL, NULL) ;
  500.  
  501.   for (sDrive = 0 ; sDrive < 26 ; sDrive++)
  502.     if (ulDriveMap & 1L << sDrive) {
  503.       szDrive [1] = (CHAR) sDrive + 'A' ;
  504.  
  505.       WinSendDlgItemMsg(hwnd,
  506.             IDD_DI_DIRS,
  507.             LM_INSERTITEM,
  508.             MPFROM2SHORT (LIT_END, 0),
  509.             MPFROMP (szDrive)) ;
  510.     }
  511.  
  512. searchMask = MUST_HAVE_DIRECTORY;
  513.   rc = DosFindFirst("*.*",&hDir,searchMask,&findbuf,sizeof (findbuf),
  514.     &usSearchCount,1L) ;
  515.   while (!rc) {
  516.     if ((findbuf.attrFile & 0x0010) &&
  517.     (findbuf.achName [0] != '.' || findbuf.achName [1]))
  518.     
  519.     WinSendDlgItemMsg (hwnd, IDD_DI_DIRS, LM_INSERTITEM,
  520.                   MPFROM2SHORT (LIT_SORTASCENDING, 0),
  521.                   MPFROMP (findbuf.achName)) ;
  522.  
  523.     rc = DosFindNext (hDir, &findbuf, sizeof findbuf, &usSearchCount) ;
  524.   }
  525. DosFindClose (hDir);
  526. } /* GetDirList*/
  527.  
  528. /* ********************************* GetFileList ************************** */
  529. VOID GetFileList(HWND hwnd) {
  530.  
  531. FILEFINDBUF3 findbuf ;
  532. HDIR        hDir = HDIR_CREATE;
  533. ULONG       usSearchCount = 1 ;
  534. APIRET        rc;
  535. ULONG        searchMask;
  536.  
  537.   WinSendDlgItemMsg (hwnd, IDD_DI_FILES, LM_DELETEALL, NULL, NULL) ;
  538.  
  539. searchMask = FILE_ARCHIVED | FILE_READONLY;
  540.   rc = DosFindFirst("*.*", &hDir, searchMask, &findbuf, sizeof findbuf,&usSearchCount,1L);
  541.   while ( !rc ) {
  542.     WinSendDlgItemMsg(hwnd,
  543.               IDD_DI_FILES,
  544.               LM_INSERTITEM,
  545.               MPFROM2SHORT (LIT_SORTASCENDING, 0),
  546.               MPFROMP (findbuf.achName)) ;
  547.  
  548.     rc = DosFindNext(hDir, &findbuf, sizeof findbuf, &usSearchCount) ;
  549.   }
  550. DosFindClose (hDir);
  551. } /* GetFileList*/
  552.  
  553. /* ***************************** ParseFileName *************************** */
  554. /*  In:    pcOut -- Pointer to parsed file spec*/
  555. /*       pcIn  -- Pointer to raw file spec*/
  556. /*  Returns 0 if bad file name*/
  557. /*        1 if nothing*/
  558. /*        else ok*/
  559. /**/
  560. /*  Note:  Changes current drive and directory to pcIn*/
  561. /**/
  562. BOOL ParseFileName (CHAR *pcOut, CHAR *pcIn) {
  563.         
  564. CHAR   *pcLastSlash;
  565. CHAR   *pcFileOnly;
  566. ULONG  ulDriveMap ;
  567. ULONG usDriveNum;
  568. ULONG usDirLen = 64;
  569.  
  570.   strupr(pcIn);
  571.   if (pcIn[0] == '\0') return(1);
  572.  
  573.   /* Get drive from input string or current drive*/
  574.   if (pcIn[1] == ':') {
  575.     if (DosSelectDisk(pcIn[0] - '@')) return(0);
  576.     pcIn += 2 ;
  577.   }
  578.   DosQCurDisk(&usDriveNum, &ulDriveMap) ;
  579.  
  580.   *pcOut++ = (CHAR) usDriveNum + '@' ;
  581.   *pcOut++ = ':' ;
  582.   *pcOut++ = '\\' ;
  583.  
  584.   /* If rest of string is empty, return error*/
  585.   if (pcIn[0] == '\0') return(1);
  586.  
  587.   /* Search for last backslash.  If none, could be directory.*/
  588.   if (NULL == (pcLastSlash = strrchr(pcIn, '\\'))) {
  589.       if (!DosSetCurrentDir(pcIn)) return(1);
  590.  
  591.     /* Otherwise, get current dir & attach input filename*/
  592.     DosQueryCurrentDir(0, pcOut, &usDirLen);
  593.     if (*(pcOut + strlen(pcOut) - 1) != '\\') strcat(pcOut++, "\\");
  594.     strcat(pcOut, pcIn) ;
  595.     return(2);
  596.   }
  597.   /* If the only backslash is at beginning, change to root*/
  598.   if (pcIn == pcLastSlash) {
  599.       DosSetCurrentDir("\\") ;
  600.     if (pcIn[1] == '\0') return(1);
  601.     strcpy(pcOut, pcIn + 1);
  602.     return(2);
  603.   }
  604.  
  605.   /* Attempt to change directory -- Get current dir if OK*/
  606.   *pcLastSlash = '\0';
  607.   if (DosSetCurrentDir(pcIn)) return(0);
  608.   DosQueryCurrentDir(0, pcOut, &usDirLen);
  609.  
  610.   /* Append input filename, if any*/
  611.   pcFileOnly = pcLastSlash + 1;
  612.   if (*pcFileOnly == '\0') return(1);
  613.   if (*(pcOut + strlen(pcOut) - 1) != '\\') strcat(pcOut++, "\\");
  614.   strcat(pcOut, pcFileOnly);
  615.   return(2);
  616. } /* ParseFileName*/
  617.  
  618. /* ******************************** CheckLSParms ************************** */
  619. /*  return true if everything is okay*/
  620. BOOL CheckLSParms(HWND hwnd, USHORT Mode) {
  621.  
  622. CHAR   szBuffer[FILENMSZ];
  623. USHORT curBuff;
  624. CHAR   curBuffName[BUFFERNMSZ];
  625. USHORT NameLen;
  626. USHORT curChar;
  627. CHAR   szFileName[FILENMSZ];
  628.  
  629.   NameLen = WinQueryDlgItemText(hwnd,
  630.                 IDD_DI_FNAME,
  631.                 FILENMSZ,
  632.                 szBuffer);
  633.  
  634.   switch (ParseFileName(szFileName, szBuffer)) {
  635.     case 0:
  636.       PutBox("Illegal file name.","");
  637.       return(FALSE);
  638.     case 1: /* no error, just don't do anything*/
  639.       return(FALSE);
  640.   }
  641.   NameLen = WinQueryDlgItemText(hwnd,
  642.                 IDD_DI_FLD,
  643.                 BUFFERNMSZ,
  644.                 curBuffName);
  645.  
  646.   if (NameLen == 0) {
  647.     PutBox("You must enter a buffer name,","or select 'Cancel'");
  648.     return(FALSE);
  649.   }
  650.  
  651.   for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  652.     curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  653.  
  654. /* set the current buffer - must base on mode 'cause save can only use*/
  655. /* existing buffers while load can create new ones*/
  656.   if (Mode == BUSY_LOAD)
  657.     for (curBuff=0;
  658.      (curBuff < NUM_IMAGES) &&
  659.      (ImageBuffers[curBuff].BufferName[0] != '\0') &&
  660.      (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  661.      curBuff++);
  662.   else
  663.     for (curBuff=0;
  664.      (curBuff < NUM_IMAGES) &&
  665.      (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  666.      curBuff++);
  667.  
  668.  
  669.   if (NameLen < 1) {
  670.     PutBox("You must select an","image buffer");
  671.     return(FALSE);
  672.   }
  673.  
  674.   if (curBuff < NUM_IMAGES) {
  675.     if (ImageBuffers[curBuff].Busy)
  676.       PutBox("That buffer is in use.","");
  677.     else {
  678.       strcpy(ImageBuffers[curBuff].FileName,szFileName);
  679.       strncpy(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ);
  680.       ImageBuffers[curBuff].DriveID[0] = ' ';
  681.       ImageBuffers[curBuff].Busy = Mode;
  682.       BufferNum = curBuff;
  683.       return(TRUE);
  684.     }
  685.   }
  686.   else
  687.     PutBox("You must select an existing","image buffer");
  688.   return(FALSE);
  689. } /* CheckLSParms*/
  690.  
  691. /* ******************************* LoadDlgProc **************************** */
  692. /*  LoadDlgProc  --  Image Buffer Load dialog procedure.*/
  693. /**/
  694. MRESULT EXPENTRY LoadDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2) {
  695.  
  696. USHORT curBuff;
  697. static CHAR szCurrentPath[FILENMSZ];
  698. static CHAR szBuffer[FILENMSZ];
  699. MRESULT  Select;
  700.  
  701.   switch (id)
  702.     {
  703.     case WM_INITDLG:
  704.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  705.       GetDirList(hwnd, szCurrentPath) ;
  706.       GetFileList(hwnd) ;
  707.  
  708.       WinSendDlgItemMsg(hwnd,
  709.             IDD_DI_FNAME,
  710.             EM_SETTEXTLIMIT,
  711.             MPFROM2SHORT (FILENMSZ, 0),
  712.             NULL) ;
  713.       WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,IDD_DI_FNAME));
  714.       return WinDefDlgProc (hwnd, id, mp1, mp2);
  715.  
  716.     case WM_CONTROL:  /* get the button that was clicked*/
  717.       switch (SHORT1FROMMP(mp1)) {
  718.     case IDD_DI_DIRS:
  719.       Select =         WinSendDlgItemMsg(hwnd,
  720.                           SHORT1FROMMP(mp1),
  721.                           LM_QUERYSELECTION,
  722.                           0L,
  723.                           0L) ;
  724.  
  725.       WinSendDlgItemMsg(hwnd,
  726.                 SHORT1FROMMP(mp1),
  727.                 LM_QUERYITEMTEXT,
  728.                 MPFROM2SHORT(Select, sizeof szBuffer),
  729.                 MPFROMP(szBuffer)) ;
  730.       switch (SHORT2FROMMP(mp1)) {
  731.         case LN_ENTER:
  732.           if (szBuffer[0] == ' ') DosSelectDisk(szBuffer[1] - '@');
  733.           else DosSetCurrentDir (szBuffer);
  734.  
  735.           GetDirList(hwnd, szCurrentPath);
  736.           GetFileList(hwnd);
  737.  
  738.           WinSetDlgItemText(hwnd, IDD_DI_FNAME, "");
  739.             return WinDefDlgProc (hwnd, id, mp1, mp2);
  740.       }
  741.       break;
  742.  
  743.     case IDD_DI_FILES:
  744.       Select =         WinSendDlgItemMsg(hwnd,
  745.                           SHORT1FROMMP(mp1),
  746.                           LM_QUERYSELECTION,
  747.                           0L,
  748.                           0L) ;
  749.  
  750.       WinSendDlgItemMsg(hwnd,
  751.                 SHORT1FROMMP(mp1),
  752.                 LM_QUERYITEMTEXT,
  753.                 MPFROM2SHORT(Select, sizeof szBuffer),
  754.                 MPFROMP(szBuffer)) ;
  755.       if (SHORT2FROMMP(mp1) == LN_SELECT)
  756.         WinSetDlgItemText(hwnd, IDD_DI_FNAME, szBuffer);
  757.       break ;
  758.  
  759.     case IDD_DI_BOX:
  760.       curBuff = SetBox(hwnd, mp1);
  761.       switch (SHORT2FROMMP(mp1)) {
  762.         case LN_SELECT:
  763.           WinSetDlgItemText(hwnd,
  764.                 IDD_DI_FLD,
  765.                 ImageBuffers[curBuff].BufferName);
  766.             return WinDefDlgProc (hwnd, id, mp1, mp2);
  767.         case LN_ENTER:
  768.           if (ImageBuffers[curBuff].Busy)
  769.         PutBox("That buffer is in use.","");
  770.           else {
  771.         if (CheckLSParms(hwnd, BUSY_LOAD)) {
  772.           WinDismissDlg(hwnd, TRUE);
  773.         }
  774.           }
  775.       }
  776.       }        /* switch on the button that was pressed */
  777.       return WinDefDlgProc (hwnd, id, mp1, mp2);
  778.  
  779.     case WM_COMMAND:
  780.       switch (COMMANDMSG(&id)->cmd)
  781.           {
  782.           case DID_OK:
  783.       if (CheckLSParms(hwnd, BUSY_LOAD)) {
  784.         WinDismissDlg(hwnd, TRUE);
  785.       }
  786.         return 0;
  787.  
  788.     case DID_CANCEL:
  789.       WinDismissDlg(hwnd, FALSE);
  790.         return 0;
  791.       } /* switch on commandID*/
  792.         break;
  793.     } /* switch on msgID*/
  794.  
  795.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  796. } /* LoadDlgProc*/
  797.  
  798. /* ******************************* SaveDlgProc ***************************** */
  799. /*  SaveDlgProc  --  Image Buffer Save dialog procedure.*/
  800. /**/
  801. MRESULT EXPENTRY SaveDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2) {
  802.  
  803. USHORT curBuff;
  804. static CHAR szCurrentPath [FILENMSZ];
  805. static CHAR szBuffer [FILENMSZ];
  806. MRESULT  Select;
  807.  
  808.   switch (id)
  809.     {
  810.     case WM_INITDLG:
  811.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  812.       GetDirList(hwnd, szCurrentPath) ;
  813.       GetFileList(hwnd) ;
  814.  
  815.       WinSendDlgItemMsg(hwnd,
  816.             IDD_DI_FNAME,
  817.             EM_SETTEXTLIMIT,
  818.             MPFROM2SHORT (FILENMSZ, 0),
  819.             NULL) ;
  820.       return(0);
  821.  
  822.     case WM_CONTROL:  /* get the button that was clicked*/
  823.       switch (SHORT1FROMMP(mp1)) {
  824.     case IDD_DI_DIRS:
  825.       Select =             WinSendDlgItemMsg(hwnd,
  826.                           SHORT1FROMMP(mp1),
  827.                           LM_QUERYSELECTION,
  828.                           0L,
  829.                           0L) ;
  830.  
  831.       WinSendDlgItemMsg(hwnd,
  832.                 SHORT1FROMMP(mp1),
  833.                 LM_QUERYITEMTEXT,
  834.                 MPFROM2SHORT(Select, sizeof szBuffer),
  835.                 MPFROMP(szBuffer)) ;
  836.       switch (SHORT2FROMMP(mp1)) {
  837.         case LN_ENTER:
  838.           if (szBuffer[0] == ' ') DosSelectDisk(szBuffer[1] - '@');
  839.           else DosSetCurrentDir (szBuffer);
  840.  
  841.           GetDirList(hwnd, szCurrentPath);
  842.           GetFileList(hwnd);
  843.  
  844.           WinSetDlgItemText(hwnd, IDD_DI_FNAME, "");
  845.           return(0);
  846.       }
  847.       break;
  848.  
  849.     case IDD_DI_FILES:
  850.       Select =             WinSendDlgItemMsg(hwnd,
  851.                           SHORT1FROMMP(mp1),
  852.                           LM_QUERYSELECTION,
  853.                           0L,
  854.                           0L) ;
  855.  
  856.       WinSendDlgItemMsg(hwnd,
  857.                 SHORT1FROMMP(mp1),
  858.                 LM_QUERYITEMTEXT,
  859.                 MPFROM2SHORT(Select, sizeof szBuffer),
  860.                 MPFROMP(szBuffer)) ;
  861.       switch (SHORT2FROMMP(mp1)) {
  862.         case LN_SELECT:
  863.           WinSetDlgItemText(hwnd, IDD_DI_FNAME, szBuffer);
  864.           return(0);
  865.  
  866.         case LN_ENTER:
  867.           if (CheckLSParms(hwnd, BUSY_SAVE)) {
  868.         WinDismissDlg(hwnd, TRUE);
  869.           }
  870.           return(0);
  871.       }
  872.       break ;
  873.  
  874.     case IDD_DI_BOX:
  875.       curBuff = SetBox(hwnd, mp1);
  876.       switch (SHORT2FROMMP(mp1)) {
  877.         case LN_SELECT:
  878.           WinSetDlgItemText(hwnd,
  879.                 IDD_DI_FLD,
  880.                 ImageBuffers[curBuff].BufferName);
  881.           return(0);
  882.         case LN_ENTER:
  883.           if (ImageBuffers[curBuff].Busy)
  884.         PutBox("That buffer is in use.","");
  885.           else {
  886.         if (CheckLSParms(hwnd, BUSY_SAVE)) {
  887.           WinDismissDlg(hwnd, TRUE);
  888.         }
  889.           }
  890.       }
  891.       } /* switch for CONTROL*/
  892.         return(0);
  893.  
  894.     case WM_COMMAND:
  895.       switch (COMMANDMSG(&id)->cmd)
  896.           {
  897.           case DID_OK:
  898.       if (CheckLSParms(hwnd, BUSY_SAVE)) {
  899.         WinDismissDlg(hwnd, TRUE);
  900.       }
  901.       return(0);
  902.  
  903.     case DID_CANCEL:
  904.          WinDismissDlg(hwnd, FALSE);
  905.       return(0);
  906.       } /* switch on commandID*/
  907.         break;
  908.     } /* switch on msgID*/
  909.  
  910.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  911. } /* SaveDlgProc*/
  912.  
  913.  
  914. /* ****************************** SetEdit ***************************** */
  915. /**/
  916. /* return the buffer number of the field in the edit box*/
  917. /**/
  918. static USHORT SetEdit(HWND hwnd, USHORT EditB) {
  919.  
  920. USHORT curBuff;
  921. USHORT curChar;
  922. CHAR   curBuffName[BUFFERNMSZ];
  923. USHORT NameLen;
  924.  
  925.   NameLen = WinQueryDlgItemText(hwnd,
  926.                 EditB,
  927.                 BUFFERNMSZ,
  928.                 curBuffName);
  929.  
  930.   if (NameLen == 0) {
  931.     PutBox("You must enter an image name,","  or select 'Cancel'");
  932.     return(NUM_IMAGES+1);
  933.   }
  934.  
  935.   for (curChar=0;curChar < BUFFERNMSZ;curChar++)
  936.     curBuffName[curChar] = (CHAR) toupper(curBuffName[curChar]);
  937.  
  938.   for (curBuff=0;
  939.        (curBuff < NUM_IMAGES) &&
  940.        (ImageBuffers[curBuff].BufferName[0] != '\0') &&
  941.        (strncmp(ImageBuffers[curBuff].BufferName,curBuffName,BUFFERNMSZ));
  942.        curBuff++) ;
  943.  
  944.   if (curBuff == NUM_IMAGES) {
  945.     PutBox("You must select an existing","image buffer");
  946.     return(NUM_IMAGES+1);
  947.   }
  948.  
  949.   if (ImageBuffers[curBuff].Busy) {
  950.     PutBox("The image is busy -","please select another");
  951.     return(NUM_IMAGES+1);
  952.   }
  953.  
  954.   return(curBuff);
  955. }
  956.  
  957. /* **************************** CompDlgProc ***************************** */
  958. /*  CompDlgProc  --  Image Buffer Compare dialog procedure.*/
  959. /**/
  960. MRESULT EXPENTRY CompDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2) {
  961.  
  962. USHORT curBuff;
  963.  
  964.   switch (id)
  965.     {
  966.     case WM_INITDLG:
  967.       GetImageList(hwnd, IDD_DI_FLD, IDD_DI_BOX);
  968.       GetImageList(hwnd, IDD_CM_FLD, IDD_CM_BOX);
  969.     WinSetDlgItemText(hwnd, IDD_CM_FLD, ImageBuffers[secondUsed].BufferName);
  970.       BufferNum = NUM_IMAGES+1;
  971.       CompNum = NUM_IMAGES+1;
  972.       return(0);
  973.  
  974.     case WM_CONTROL:  /* get the button that was clicked*/
  975.       curBuff = SetBox(hwnd, mp1);
  976.       switch (SHORT1FROMMP(mp1)) {
  977.  
  978.     case IDD_DI_BOX:
  979.       switch (SHORT2FROMMP(mp1)) {
  980.         case LN_SELECT:
  981.           WinSetDlgItemText(hwnd,
  982.                 IDD_DI_FLD,
  983.                 ImageBuffers[curBuff].BufferName);
  984.           return(0);
  985.         case LN_ENTER:
  986.           BufferNum = SetEdit(hwnd, IDD_DI_FLD);
  987.           CompNum    = SetEdit(hwnd, IDD_CM_FLD);
  988.           if ((CompNum == NUM_IMAGES+1) ||
  989.           (CompNum == BufferNum))
  990.         PutBox("You must select two","different (and existing) images");
  991.           else {
  992.         ImageBuffers[BufferNum].Busy = BUSY_COMP;
  993.         ImageBuffers[CompNum].Busy = BUSY_COMP;
  994.         WinDismissDlg(hwnd, TRUE);
  995.           }
  996.       }
  997.       break;
  998.     case IDD_CM_BOX:
  999.       switch (SHORT2FROMMP(mp1)) {
  1000.         case LN_SELECT:
  1001.           WinSetDlgItemText(hwnd,
  1002.                 IDD_CM_FLD,
  1003.                 ImageBuffers[curBuff].BufferName);
  1004.           CompNum = curBuff;
  1005.           return(0);
  1006.         case LN_ENTER:
  1007.           BufferNum = SetEdit(hwnd, IDD_DI_FLD);
  1008.           CompNum    = SetEdit(hwnd, IDD_CM_FLD);
  1009.           if ((BufferNum == NUM_IMAGES+1) ||
  1010.           (BufferNum == CompNum))
  1011.         PutBox("You must select two","different (and existing) images");
  1012.           else {
  1013.         ImageBuffers[BufferNum].Busy = BUSY_COMP;
  1014.         ImageBuffers[CompNum].Busy = BUSY_COMP;
  1015.         WinDismissDlg(hwnd, TRUE);
  1016.           }
  1017.       }
  1018.       break;
  1019.       } /* switch for CONTROL*/
  1020.         return(0);
  1021.  
  1022.     case WM_COMMAND:
  1023.       switch (COMMANDMSG(&id)->cmd)
  1024.           {
  1025.           case DID_OK:
  1026.         if (setUpCompare (hwnd))
  1027.       return(0);
  1028.         else
  1029.             {WinDismissDlg(hwnd, TRUE);
  1030.             return 0;
  1031.             }
  1032.  
  1033.     case DID_CANCEL:
  1034.          WinDismissDlg(hwnd, FALSE);
  1035.       return(0);
  1036.       } /* switch on commandID*/
  1037.         break;
  1038.     } /* switch on msgID*/
  1039.  
  1040.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  1041. } /* CompDlgProc*/
  1042.  
  1043. /* ****************************** AboutDlgProc ************************** */
  1044. /*  AboutDlgProc  --  About box dialog procedure.*/
  1045. /**/
  1046. MRESULT EXPENTRY AboutDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  1047. {
  1048.  
  1049.   switch (id)
  1050.     {
  1051.     case WM_COMMAND:
  1052.       switch (COMMANDMSG(&id)->cmd)
  1053.           {
  1054.           case DID_OK:
  1055.     case DID_CANCEL:
  1056.          WinDismissDlg(hwnd, TRUE);
  1057.       return 0;
  1058.       } /* switch on commandID*/
  1059.         break;
  1060.     } /* switch on msgID*/
  1061.  
  1062.   return(WinDefDlgProc(hwnd, id, mp1, mp2));
  1063. } /* AboutDlgProc*/
  1064.  
  1065. /* *************************** duplicateDlgProc *********************** */
  1066. MRESULT EXPENTRY duplicateDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  1067. {int        sourceBuff,
  1068.             destBuff;
  1069.  
  1070. switch (id)
  1071.     {
  1072. case WM_INITDLG:
  1073.     GetImageList(hwnd, 0, IDD_DI_T2);
  1074.     GetImageList(hwnd, 0, IDD_DI_T3);
  1075.     WinSendDlgItemMsg (hwnd, IDD_DI_T2, LM_SELECTITEM, (MPARAM) 0, (MPARAM)TRUE);
  1076.     WinSendDlgItemMsg (hwnd, IDD_DI_T3, LM_SELECTITEM, (MPARAM) 1, (MPARAM)TRUE);
  1077.     WinSetWindowText (WinWindowFromID ( hwnd, IDD_DI_DRV), DiskName);
  1078.     BufferNum = NUM_IMAGES+1;
  1079.     CompNum = NUM_IMAGES+1;
  1080.     return(0);
  1081. case WM_COMMAND:
  1082.     switch (COMMANDMSG(&id)->cmd)
  1083.           {
  1084.       case IDD_DI_OK:
  1085.         sourceBuff = getImageNum (hwnd, IDD_DI_T2);
  1086.         destBuff = getImageNum (hwnd, IDD_DI_T3);
  1087.         if (sourceBuff == destBuff)
  1088.             {WinMessageBox (HWND_DESKTOP, hwnd, "Images must be different", " ",
  1089.                 0, MB_OK);
  1090.             if (!ImageBuffers[destBuff].diskBuffer)
  1091.                 ImageBuffers[destBuff].BufferName[0] = 0;
  1092.             return (MRESULT)1;
  1093.             }
  1094.         if (SetDrive (hwnd, sourceBuff) == TRUE)
  1095.             {if (!ImageBuffers[sourceBuff].diskBuffer)
  1096.                 ImageBuffers[sourceBuff].BufferName[0] = 0;
  1097.             if (!ImageBuffers[destBuff].diskBuffer)
  1098.                 ImageBuffers[destBuff].BufferName[0] = 0;
  1099.             WinDismissDlg (hwnd, FALSE);
  1100.             return 0;
  1101.             }
  1102.         ImageBuffers[destBuff].DriveID[0] = ImageBuffers[sourceBuff].DriveID[0];
  1103.         BufferNum = sourceBuff;
  1104.         CompNum = destBuff;
  1105.         WinDismissDlg(hwnd, TRUE);
  1106.         return 0;
  1107.     case IDD_DI_CANCEL:
  1108.         WinDismissDlg(hwnd, FALSE);
  1109.         return (MRESULT) 1;
  1110.         } /* switch on commandID*/
  1111.         break;
  1112.     } /* switch on msgID*/
  1113.  
  1114. return(WinDefDlgProc(hwnd, id, mp1, mp2));
  1115. }
  1116.  
  1117. /* ***************************** copyCheckDlgProc ************************ */
  1118. MRESULT EXPENTRY copyCheckDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  1119. {int        sourceBuff,
  1120.             destBuff;
  1121.  
  1122. switch (id)
  1123.     {
  1124. case WM_INITDLG:
  1125.     GetImageList(hwnd, 0, IDD_DI_T2);
  1126.     GetImageList(hwnd, 0, IDD_DI_T3);
  1127.     WinSendDlgItemMsg (hwnd, IDD_DI_T2, LM_SELECTITEM, (MPARAM) 0, (MPARAM)TRUE);
  1128.     WinSendDlgItemMsg (hwnd, IDD_DI_T3, LM_SELECTITEM, (MPARAM) 1, (MPARAM)TRUE);
  1129.     WinSetWindowText (WinWindowFromID ( hwnd, IDD_DI_DRV), DiskName);
  1130.     BufferNum = NUM_IMAGES+1;
  1131.     CompNum = NUM_IMAGES+1;
  1132.     return(0);
  1133. case WM_COMMAND:
  1134.     switch (COMMANDMSG(&id)->cmd)
  1135.           {
  1136.       case IDD_DI_OK:
  1137.         sourceBuff = getImageNum (hwnd, IDD_DI_T2);
  1138.         if ( (sourceBuff>=NUM_IMAGES) || (!ImageBuffers[sourceBuff].diskBuffer ) )
  1139.             {WinMessageBox (HWND_DESKTOP, hwnd, "Image must exist", " ",
  1140.                 0, MB_OK);
  1141.             ImageBuffers[sourceBuff].BufferName[0] = 0;
  1142.             return (MRESULT)1;
  1143.             }
  1144.         destBuff = getImageNum (hwnd, IDD_DI_T3);
  1145.         if (sourceBuff == destBuff)
  1146.             {WinMessageBox (HWND_DESKTOP, hwnd, "Images must be different", " ",
  1147.                 0, MB_OK);
  1148.             if (!ImageBuffers[destBuff].diskBuffer)
  1149.                 ImageBuffers[destBuff].BufferName[0] = 0;
  1150.             return (MRESULT)1;
  1151.             }
  1152.         if (SetDrive (hwnd, sourceBuff) == TRUE)
  1153.             {if (!ImageBuffers[sourceBuff].diskBuffer)
  1154.                 ImageBuffers[sourceBuff].BufferName[0] = 0;
  1155.             if (!ImageBuffers[destBuff].diskBuffer)
  1156.                 ImageBuffers[destBuff].BufferName[0] = 0;
  1157.             WinDismissDlg (hwnd, FALSE);
  1158.             return 0;
  1159.             }
  1160.         ImageBuffers[destBuff].DriveID[0] = ImageBuffers[sourceBuff].DriveID[0];
  1161.         BufferNum = sourceBuff;
  1162.         CompNum = destBuff;
  1163.         WinDismissDlg(hwnd, TRUE);
  1164.         return 0;
  1165.     case IDD_DI_CANCEL:
  1166.         WinDismissDlg(hwnd, FALSE);
  1167.         return (MRESULT) 1;
  1168.         } /* switch on commandID*/
  1169.     break;
  1170.     } /* switch on msgID*/
  1171.  
  1172. return(WinDefDlgProc(hwnd, id, mp1, mp2));
  1173. }
  1174.  
  1175. /* ***************************** fileToFloppyDlgProc ************************ */
  1176. MRESULT EXPENTRY fileToFloppyDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  1177. {int        sourceBuff,
  1178.             destBuff;
  1179. FILESTATUS3    fileStat;
  1180.  
  1181. switch (id)
  1182.     {HDIR            hdir;
  1183.     FILEFINDBUF3    findBuff;
  1184.     APIRET            rc;
  1185.     ULONG            found;
  1186.     HWND            controlHandle;
  1187.     
  1188. case WM_INITDLG:
  1189.     GetImageList(hwnd, 0, IDD_CBIMAGE1);
  1190.     GetImageList(hwnd, 0, IDD_CBIMAGE2);
  1191.     WinSendDlgItemMsg (hwnd, IDD_CBIMAGE1, LM_SELECTITEM, (MPARAM) 0, (MPARAM)TRUE);
  1192.     WinSendDlgItemMsg (hwnd, IDD_CBIMAGE2, LM_SELECTITEM, (MPARAM) 1, (MPARAM)TRUE);
  1193.     WinSetWindowText (WinWindowFromID ( hwnd, IDD_DI_DRV), DiskName);
  1194.     WinSetDlgItemText (hwnd, IDD_EF_DISKFILE, imageFileName);
  1195.     BufferNum = NUM_IMAGES+1;
  1196.     CompNum = NUM_IMAGES+1;
  1197.     controlHandle = WinWindowFromID( hwnd, IDD_EF_DISKFILE);
  1198.     hdir = 0xffffffff;
  1199.     found = 1;
  1200.     if (DosFindFirst ("*", &hdir, FILE_READONLY, (PVOID) &findBuff, 
  1201.             sizeof (FILEFINDBUF3), &found, FIL_STANDARD))
  1202.         {WinMessageBox (HWND_DESKTOP, hwnd, "No files in Directory",
  1203.             " ", 0, MB_OK);
  1204.         return 0;
  1205.         }
  1206.     for (rc=0;    !rc;    )
  1207.         {WinSendMsg (controlHandle, LM_INSERTITEM, (MPARAM) LIT_SORTASCENDING,
  1208.                 (MPARAM) findBuff.achName);
  1209.         rc = DosFindNext (hdir, (PVOID) &findBuff, sizeof (FILEFINDBUF3), &found);
  1210.         }
  1211.     
  1212.     DosFindClose (hdir);
  1213.     return(0);
  1214. case WM_COMMAND:
  1215.     switch (COMMANDMSG(&id)->cmd)
  1216.           {
  1217.       case IDD_PBSTART:
  1218.         if (!WinQueryDlgItemText (hwnd, IDD_EF_DISKFILE, FILENMSZ-1, imageFileName) )
  1219.             {WinMessageBox (HWND_DESKTOP, hwnd, "A file must be specified",
  1220.                 " ", 0, MB_OK);
  1221.             return 0;
  1222.             }
  1223.         if (DosQueryPathInfo (imageFileName, 1, (PVOID) &fileStat,
  1224.                 sizeof (FILESTATUS3) ))
  1225.             {WinMessageBox (HWND_DESKTOP, hwnd, "File does not exist", " ",
  1226.                 0, MB_OK);
  1227.             return 0;
  1228.             }
  1229.         sourceBuff = getImageNum (hwnd, IDD_CBIMAGE1);
  1230.         destBuff = getImageNum (hwnd, IDD_CBIMAGE2);
  1231.         strcpy (ImageBuffers[sourceBuff].FileName, imageFileName);
  1232.         if (sourceBuff == destBuff)
  1233.             {WinMessageBox (HWND_DESKTOP, hwnd, "Images must be different", " ",
  1234.                 0, MB_OK);
  1235.             return (MRESULT)1;
  1236.             }
  1237.         if (SetDrive (hwnd, sourceBuff) == TRUE)
  1238.             return 0;
  1239.         ImageBuffers[destBuff].DriveID[0] = ImageBuffers[sourceBuff].DriveID[0];
  1240.         BufferNum = sourceBuff;
  1241.         CompNum = destBuff;
  1242.         WinDismissDlg(hwnd, TRUE);
  1243.         return 0;
  1244.     case IDD_PBCANCEL:
  1245.         WinDismissDlg(hwnd, FALSE);
  1246.         return (MRESULT) 1;
  1247.         } /* switch on commandID*/
  1248.     break;
  1249.     } /* switch on msgID*/
  1250.  
  1251. return(WinDefDlgProc(hwnd, id, mp1, mp2));
  1252. }
  1253.  
  1254. /* ***************************** floppyToFileDlgProc ************************ */
  1255. MRESULT EXPENTRY floppyToFileDlgProc(HWND hwnd, ULONG id, MPARAM mp1, MPARAM mp2)
  1256. {int        sourceBuff,
  1257.             destBuff;
  1258. FILESTATUS3    fileStat;
  1259.  
  1260. switch (id)
  1261.     {
  1262. case WM_INITDLG:
  1263.     GetImageList(hwnd, 0, IDD_CBIMAGE1);
  1264.     GetImageList(hwnd, 0, IDD_CBIMAGE2);
  1265.     WinSendDlgItemMsg (hwnd, IDD_CBIMAGE1, LM_SELECTITEM, (MPARAM) 0, (MPARAM)TRUE);
  1266.     WinSendDlgItemMsg (hwnd, IDD_CBIMAGE2, LM_SELECTITEM, (MPARAM) 1, (MPARAM)TRUE);
  1267.     WinSetWindowText (WinWindowFromID ( hwnd, IDD_DI_DRV), DiskName);
  1268.     WinSetDlgItemText (hwnd, IDD_EF_DISKFILE, imageFileName);
  1269.     BufferNum = NUM_IMAGES+1;
  1270.     CompNum = NUM_IMAGES+1;
  1271.     return(0);
  1272. case WM_COMMAND:
  1273.     switch (COMMANDMSG(&id)->cmd)
  1274.           {
  1275.       case IDD_PBSTART:
  1276.         if (!WinQueryDlgItemText (hwnd, IDD_EF_DISKFILE, FILENMSZ-1, imageFileName) )
  1277.             {WinMessageBox (HWND_DESKTOP, hwnd, "A file must be specified",
  1278.                 " ", 0, MB_OK);
  1279.             return 0;
  1280.             }
  1281.         if ( !DosQueryPathInfo (imageFileName, 1, (PVOID) &fileStat,
  1282.                 sizeof (FILESTATUS3) ))
  1283.             {if (WinMessageBox (HWND_DESKTOP, hwnd, "File exists - Overwrite?", " ",
  1284.                 0, MB_YESNO) == MBID_NO)
  1285.                 return 0;
  1286.             }
  1287.         sourceBuff = getImageNum (hwnd, IDD_CBIMAGE1);
  1288.         destBuff = getImageNum (hwnd, IDD_CBIMAGE2);
  1289.         if (sourceBuff == destBuff)
  1290.             {WinMessageBox (HWND_DESKTOP, hwnd, "Images must be different", " ",
  1291.                 0, MB_OK);
  1292.             return (MRESULT)1;
  1293.             }
  1294.         if (SetDrive (hwnd, sourceBuff) == TRUE)
  1295.             return 0;
  1296.         ImageBuffers[destBuff].DriveID[0] = ImageBuffers[sourceBuff].DriveID[0];
  1297.     strcpy (ImageBuffers[sourceBuff].FileName, imageFileName);
  1298.         BufferNum = sourceBuff;
  1299.         CompNum = destBuff;
  1300.         WinDismissDlg(hwnd, TRUE);
  1301.         return 0;
  1302.     case IDD_PBCANCEL:
  1303.         WinDismissDlg(hwnd, FALSE);
  1304.         return (MRESULT) 1;
  1305.         } /* switch on commandID*/
  1306.     break;
  1307.     } /* switch on msgID*/
  1308.  
  1309. return(WinDefDlgProc(hwnd, id, mp1, mp2));
  1310. }
  1311.  
  1312.  
  1313. /* ***************************** setUpCompare ************************* */
  1314. /* do initialization to compare two disk images */
  1315.  
  1316. int        setUpCompare (HWND hwnd)
  1317.  
  1318. {
  1319. BufferNum = SetEdit(hwnd, IDD_DI_FLD);
  1320. CompNum   = SetEdit(hwnd, IDD_CM_FLD);
  1321. if ((CompNum == NUM_IMAGES+1) ||
  1322.   (CompNum == BufferNum))
  1323.  
  1324.     {PutBox("You must select two","different (and existing) images");
  1325.     return 1;
  1326.     }
  1327. else {
  1328.     ImageBuffers[BufferNum].Busy = BUSY_COMP;
  1329.     ImageBuffers[CompNum].Busy = BUSY_COMP;
  1330.     return 0;
  1331.     }
  1332. }
  1333.