home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / os2 / filedlg5 / source / finddlg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-11  |  26.1 KB  |  609 lines

  1. /****************************************************************************
  2.  * FINDDLG.C - Find file dialog box routines.                               *
  3.  *                                                                          *
  4.  *  Notes -                                                                 *
  5.  *      This following functions will have to be modified in order to       *
  6.  *      support OS/2 v1.2 long file names :                                 *
  7.  *                                                                          *
  8.  *              Directory()                                                 *
  9.  *                                                                          *
  10.  *  Modifications -                                                         *
  11.  *      21-Sep-1989 : Moved find file functions into separate file.         *
  12.  *                    Made default button context sensitive.                *
  13.  *                    Prevented buttons from retaining focus after being    *
  14.  *                      clicked.                                            *
  15.  *                    Fixed bug that caused duplicate error messages to     *
  16.  *                      be displayed when enter key used to select list     *
  17.  *                      box items.                                          *
  18.  *      11-Oct-1989 : Changed to DLL version of ErrMessageBox function.     *
  19.  *                                                                          *
  20.  * (c)Copyright 1989 Rick Yoder                                             *
  21.  ****************************************************************************/
  22.  
  23.     #define INCL_WIN
  24.     #define INCL_DOS
  25.     #define INCL_DOSERRORS
  26.     #include <os2.h>
  27.  
  28.     #include <string.h>
  29.     #include <errmsg.h>
  30.  
  31.     #include "filedlg.h"
  32.     #include "dialog.h"
  33.     #include "tools.h"
  34.     #include "static.h"
  35.     #include "opendata.h"   // definition of structure holding dialog box
  36.                             //  static data (DATA & PDATA types).
  37.  
  38. /****************************************************************************
  39.  *  Procedure declarations                                                  *
  40.  ****************************************************************************/
  41.     static MRESULT near FindInit( HWND hwnd,MPARAM mp2 );
  42.     static MRESULT near PatternEditCtrl( HWND hwnd,USHORT msg,
  43.                                          MPARAM mp1,MPARAM mp2 );
  44.     static MRESULT near FindListbox( HWND hwnd,USHORT msg,
  45.                                      MPARAM mp1,MPARAM mp2 );
  46.     static MRESULT near SearchButton( HWND hwnd );
  47.     static MRESULT near OpenButton( HWND hwnd );
  48.     static void near ResetDefaultButton( HWND hwnd );
  49.     static BOOL near Directory( HWND hDlg,PSZ pszFileSpec,PDATA pData );
  50.     static USHORT near OpenFile( HWND hDlg,PDATA pData );
  51. /****************************************************************************/
  52.  
  53.  
  54. /****************************************************************************
  55.  * _FindDlgProc()                                                           *
  56.  ****************************************************************************/
  57.     MRESULT CALLBACK _FindDlgProc( HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2 )
  58.     {
  59.         PDATA   pData;
  60.  
  61.         switch ( msg ) {
  62.             case WM_INITDLG:
  63.                 return FindInit( hwnd,mp2 );
  64.  
  65.             case WM_CHAR:
  66.                 if ( CHARMSG(&msg)->fs & KC_ALT )
  67.                     switch ( CHARMSG(&msg)->chr ) {
  68.                         case 'p':
  69.                         case 'P': WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,FIND_PATTERN));
  70.                                   return 0;
  71.  
  72.                         case 'd':
  73.                         case 'D': WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,FIND_DRIVES));
  74.                                   return 0;
  75.  
  76.                         case 'f':
  77.                         case 'F': WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,FIND_FLIST));
  78.                                   return 0;
  79.                         }
  80.                 break;
  81.  
  82.             case WM_CONTROL:
  83.                 switch ( SHORT1FROMMP(mp1) ) {
  84.                     case FIND_PATTERN:
  85.                         return PatternEditCtrl( hwnd,msg,mp1,mp2 );
  86.  
  87.                     case FIND_FLIST:
  88.                         return FindListbox( hwnd,msg,mp1,mp2 );
  89.  
  90.                     case FIND_DRIVES:
  91.                         if ( SHORT2FROMMP(mp1) == LN_SETFOCUS )
  92.                             ResetDefaultButton( hwnd );
  93.                         break;
  94.                     }
  95.                 break;
  96.  
  97.             case WM_COMMAND:
  98.                 pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
  99.                 switch (COMMANDMSG(&msg)->cmd) {
  100.                     case FIND_SEARCH:
  101.                         return SearchButton( hwnd );
  102.  
  103.                     case FIND_OPEN:
  104.                         return OpenButton( hwnd );
  105.  
  106.                     case DID_CANCEL:
  107.                     case FIND_CANCEL:
  108.                         WinDismissDlg( hwnd,FDLG_CANCEL );
  109.                         return 0;
  110.                     }
  111.                 break;
  112.             }
  113.  
  114.         return WinDefDlgProc( hwnd,msg,mp1,mp2 );
  115.     }
  116. /****************************************************************************/
  117.  
  118.  
  119. /****************************************************************************
  120.  * FindInit() -- Process WM_INITDLG message sent to find file dialog box.   *
  121.  ****************************************************************************/
  122.     static MRESULT near FindInit( HWND hwnd,MPARAM mp2 )
  123.     {
  124.         PDATA   pData;
  125.         USHORT  usResult,usCount,usIndex,usDriveNum;
  126.         ULONG   ulMap;
  127.  
  128.         pData = PVOIDFROMMP( mp2 );
  129.         WinSetWindowULong( hwnd,QWL_USER,(ULONG)pData );
  130.         WinSendDlgItemMsg( hwnd,FIND_FLIST,LM_DELETEALL,NULL,NULL );
  131.         WinSendDlgItemMsg( hwnd,FIND_DRIVES,LM_DELETEALL,NULL,NULL );
  132.         WinSetDlgItemText( hwnd,FIND_PATTERN,pData->pszShowSpec );
  133.         WinEnableWindow( WinWindowFromID(hwnd,FIND_OPEN),FALSE );
  134.         WinSetWindowUShort( WinWindowFromID(hwnd,FIND_OPEN),QWS_USER,TRUE );
  135.         pData->usSelectFind = 0;
  136.  
  137.         /* Fill in disk drive list box */
  138.         if ( usResult = DosQCurDisk(&usDriveNum,&ulMap) )
  139.             {
  140.             ErrMessageBox( hwnd,szSearchTitle,usResult,NULL,0 );
  141.             WinDismissDlg( hwnd,FDLG_CANCEL );
  142.             return 0L;
  143.             }
  144.         pData->pszScratch[1] = ':';
  145.         pData->pszScratch[2] = '\0';
  146.         for ( usCount = 0; usCount < 26; usCount++ )
  147.             if ( ulMap & 1L << usCount )
  148.                 {
  149.                 pData->pszScratch[0] = (CHAR)usCount + 'A';
  150.  
  151.                 usIndex = SHORT1FROMMR(
  152.                             WinSendDlgItemMsg( hwnd,FIND_DRIVES,
  153.                                                LM_INSERTITEM,
  154.                                                MPFROMSHORT(LIT_END),
  155.                                                MPFROMP(pData->pszScratch) )
  156.                                       );
  157.  
  158.                 if ( usCount == usDriveNum-1 )
  159.                     {
  160.                     WinSendDlgItemMsg( hwnd,FIND_DRIVES,
  161.                                        LM_SELECTITEM,
  162.                                        MPFROMSHORT(usIndex),
  163.                                        MPFROMSHORT(TRUE) );
  164.                     }
  165.                 }
  166.  
  167.         return 0L;
  168.     }
  169. /****************************************************************************/
  170.  
  171.  
  172. /****************************************************************************
  173.  * PatternEditCtrl() -- Handles messages sent by FIND_PATTERN edit control  *
  174.  *                      to find file dialog box.                            *
  175.  ****************************************************************************/
  176.     static MRESULT near PatternEditCtrl( HWND hwnd,USHORT msg,
  177.                                          MPARAM mp1,MPARAM mp2 )
  178.     {
  179.         PDATA   pData;
  180.         USHORT  usLen;
  181.  
  182.         pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
  183.         switch ( SHORT2FROMMP(mp1) ) {
  184.             case EN_CHANGE:
  185.                 WinEnableWindow( WinWindowFromID(hwnd,FIND_PATTERN),
  186.                                  WinQueryDlgItemTextLength(hwnd,FIND_PATTERN)
  187.                                );
  188.                 break;
  189.  
  190.             case EN_SETFOCUS:
  191.                 usLen = WinQueryDlgItemTextLength( hwnd,FIND_PATTERN );
  192.                 WinSendDlgItemMsg( hwnd,FIND_PATTERN,EM_SETSEL,
  193.                                    MPFROM2SHORT(0,usLen),0L );
  194.                 ResetDefaultButton( hwnd );
  195.                 break;
  196.             }
  197.  
  198.         return WinDefDlgProc( hwnd,msg,mp1,mp2 );
  199.     }
  200. /****************************************************************************/
  201.  
  202.  
  203. /****************************************************************************
  204.  * FindListbox() -- Handle messages sent by FIND_FLIST list box to the      *
  205.  *                  find file dialog box.                                   *
  206.  ****************************************************************************/
  207.     static MRESULT near FindListbox( HWND hwnd,USHORT msg,
  208.                                      MPARAM mp1,MPARAM mp2 )
  209.     {
  210.         PDATA   pData;
  211.         USHORT  usResult;
  212.  
  213.         pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
  214.         switch ( SHORT2FROMMP(mp1) ) {
  215.             case LN_SELECT:
  216.                 usResult = (USHORT)WinSendDlgItemMsg( hwnd,FIND_FLIST,
  217.                                                       LM_QUERYSELECTION,
  218.                                                       0L,0L );
  219.                 if ( usResult != LIT_NONE )
  220.                     pData->usSelectFind = usResult;
  221.                 WinSendDlgItemMsg( hwnd,FIND_FLIST,
  222.                                    LM_QUERYITEMTEXT,
  223.                                    MPFROM2SHORT(pData->usSelectFind,pData->usMaxPathLen+2),
  224.                                    MPFROMP(pData->pszScratch) );
  225.                 WinEnableWindow( WinWindowFromID(hwnd,FIND_OPEN),
  226.                                  (*pData->pszScratch == ' ') );
  227.                 return 0L;
  228.  
  229.             case LN_ENTER:  /* equivalent to open button clicked */
  230.                 WinSendDlgItemMsg( hwnd,FIND_OPEN,BM_CLICK,0L,0L );
  231.                 return 0L;
  232.  
  233.             case LN_SETFOCUS:
  234.                 usResult = (USHORT)WinSendDlgItemMsg( hwnd,FIND_FLIST,
  235.                                                       LM_QUERYTOPINDEX,
  236.                                                       0L,0L );
  237.                 if ( usResult != LIT_NONE )
  238.                     {
  239.                     if ( pData->usSelectFind < usResult )
  240.                         pData->usSelectFind = usResult;
  241.                     else if (pData->usSelectFind > usResult+11)
  242.                         pData->usSelectFind = usResult+11;
  243.  
  244.                     WinSendDlgItemMsg( hwnd,FIND_FLIST,
  245.                                        LM_SELECTITEM,
  246.                                        MPFROMSHORT(pData->usSelectFind),
  247.                                        MPFROMSHORT(TRUE) );
  248.                     }
  249.  
  250.                 /* Make OPEN button the current default button */
  251.                 WinSendDlgItemMsg( hwnd,FIND_SEARCH,BM_SETDEFAULT,
  252.                                    MPFROMSHORT(FALSE),0L );
  253.                 WinSendDlgItemMsg( hwnd,FIND_OPEN,BM_SETDEFAULT,
  254.                                    MPFROMSHORT(TRUE),0L );
  255.                 WinSendDlgItemMsg( hwnd,FIND_CANCEL,BM_SETDEFAULT,
  256.                                    MPFROMSHORT(FALSE),0L );
  257.                 return 0L;
  258.             }
  259.  
  260.         return WinDefDlgProc( hwnd,msg,mp1,mp2 );
  261.     }
  262. /****************************************************************************/
  263.  
  264.  
  265. /****************************************************************************
  266.  * SearchButton() -- Executed whenever SEARCH button in find file dialog    *
  267.  *                   box is clicked.                                        *
  268.  ****************************************************************************/
  269.     static MRESULT near SearchButton( HWND hwnd )
  270.     {
  271.         PDATA       pData;
  272.         HPOINTER    hptrOld;
  273.         SHORT       iItem;
  274.         USHORT      rc;
  275.         SEL         sel;
  276.         PSZ         pszFileSpec;
  277.         BOOL        fContinue;
  278.  
  279.         pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
  280.  
  281.     /* Allocate memory for file search spec. */
  282.         if ( rc = DosAllocSeg(pData->usMaxPathLen,&sel,SEG_NONSHARED) )
  283.             {
  284.             ErrMessageBox( hwnd,szSearchTitle,rc,NULL,0 );
  285.             return 0L;
  286.             }
  287.         pszFileSpec = MAKEP( sel,0 );
  288.  
  289.     /* Disable open button & change cursor to hourglass */
  290.         WinEnableWindow( WinWindowFromID(hwnd,FIND_OPEN),FALSE );
  291.         hptrOld = WinQueryPointer( HWND_DESKTOP );
  292.         WinSetPointer( HWND_DESKTOP,
  293.                        WinQuerySysPointer(HWND_DESKTOP,SPTR_WAIT,FALSE) );
  294.  
  295.     /* Retrieve current search pattern */
  296.         WinQueryDlgItemText( hwnd,FIND_PATTERN,
  297.                              pData->usMaxPathLen-3,
  298.                              pszFileSpec+3 );
  299.  
  300.     /* Erase current file list */
  301.         WinSendDlgItemMsg( hwnd,FIND_FLIST,LM_DELETEALL,0L,0L );
  302.         pData->usSelectFind = 0;
  303.  
  304.     /* Perform search on each selected drive */
  305.         iItem = (SHORT)WinSendDlgItemMsg( hwnd,FIND_DRIVES,
  306.                                           LM_QUERYSELECTION,
  307.                                           MPFROMSHORT(LIT_FIRST),0L );
  308.         fContinue = TRUE;
  309.         while ( (iItem != LIT_NONE) && fContinue )
  310.             {
  311.             WinSendDlgItemMsg( hwnd,FIND_DRIVES,
  312.                                LM_QUERYITEMTEXT,
  313.                                MPFROM2SHORT(iItem,3),
  314.                                MPFROMP(pszFileSpec) );
  315.             *(pszFileSpec+2) = '\\';
  316.             fContinue = Directory( hwnd,pszFileSpec,pData );
  317.             iItem = (SHORT)WinSendDlgItemMsg( hwnd,FIND_DRIVES,
  318.                                               LM_QUERYSELECTION,
  319.                                               MPFROMSHORT(iItem),0L );
  320.             }
  321.  
  322.     /* Free file spec. memory block */
  323.         DosFreeSeg( sel );
  324.  
  325.     /* Restore cursor to previous value */
  326.         WinSetPointer( HWND_DESKTOP,hptrOld );
  327.  
  328.     /* Display message if no files were found */
  329.     /*  and set focus to appropriate control  */
  330.         if ( fContinue )
  331.             {
  332.             if ( !WinSendDlgItemMsg(hwnd,FIND_FLIST,LM_QUERYITEMCOUNT,0L,0L) )
  333.                 {
  334.                 ErrMessageBox( hwnd,szSearchTitle,NO_FILES_FOUND,
  335.                                appMsgList,appMsgCount );
  336.                 WinSetFocus( HWND_DESKTOP,WinWindowFromID(hwnd,FIND_PATTERN) );
  337.                 }
  338.             else
  339.                 WinSetFocus( HWND_DESKTOP,WinWindowFromID(hwnd,FIND_FLIST) );
  340.             }
  341.         else
  342.             WinSetFocus( HWND_DESKTOP,WinWindowFromID(hwnd,FIND_PATTERN) );
  343.  
  344.         return 0L;
  345.     }
  346. /****************************************************************************/
  347.  
  348.  
  349. /****************************************************************************
  350.  * OpenButton() -- Executed whenever OPEN button in find file dialog        *
  351.  *                 box is clicked.                                          *
  352.  ****************************************************************************/
  353.     static MRESULT near OpenButton( HWND hwnd )
  354.     {
  355.         PDATA   pData;
  356.         SHORT   iItem;
  357.         HWND    hwndButton;
  358.  
  359.     /* Skip procedure when button does not have the focus.      *
  360.      * This prevents the duplicate error message problem that   *
  361.      * occurs when the enter key is used to select a list box   *
  362.      * item.                                                    */
  363.         hwndButton = WinWindowFromID( hwnd,FIND_OPEN );
  364.         if ( hwndButton != WinQueryFocus(HWND_DESKTOP,FALSE) ) return 0L;
  365.  
  366.         pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
  367.         iItem = pData->usSelectFind;
  368.  
  369.         if ( WinSendDlgItemMsg( hwnd,FIND_FLIST,
  370.                                 LM_QUERYITEMTEXT,
  371.                                 MPFROM2SHORT(iItem,pData->usMaxPathLen),
  372.                                 MPFROMP(pData->pszFile) )
  373.            )
  374.             {
  375.             /* Get path name */
  376.             do  {
  377.                 WinSendDlgItemMsg( hwnd,FIND_FLIST,
  378.                                    LM_QUERYITEMTEXT,
  379.                                    MPFROM2SHORT(--iItem,pData->usMaxPathLen),
  380.                                    MPFROMP(pData->pszScratch) );
  381.                 } while ( *pData->pszScratch == ' ' );
  382.             strcat( pData->pszScratch,szSlash );
  383.             strcat( pData->pszScratch,pData->pszFile+3 );
  384.  
  385.             if ( !OpenFile(hwnd,pData) )
  386.                 WinDismissDlg( hwnd,FDLG_OK );
  387.             else
  388.                 WinSetFocus( HWND_DESKTOP,WinWindowFromID(hwnd,FIND_FLIST) );
  389.             }
  390.  
  391.         return 0L;
  392.     }
  393. /****************************************************************************/
  394.  
  395.  
  396. /****************************************************************************
  397.  * ResetDefaultButton() - This function makes the SEARCH button the current *
  398.  *                        default button.                                   *
  399.  ****************************************************************************/
  400.     static void near ResetDefaultButton( HWND hwnd )
  401.     {
  402.         ULONG ulStyle;
  403.  
  404.         ulStyle = WinQueryWindowULong( WinWindowFromID(hwnd,FIND_SEARCH),
  405.                                        QWL_STYLE );
  406.         if ( !(ulStyle & BS_DEFAULT) )
  407.             {
  408.             WinSendDlgItemMsg( hwnd,FIND_SEARCH,BM_SETDEFAULT,
  409.                                MPFROMSHORT(TRUE),0L );
  410.             ulStyle = WinQueryWindowULong( WinWindowFromID(hwnd,FIND_OPEN),
  411.                                            QWL_STYLE );
  412.             WinSendDlgItemMsg( hwnd,
  413.                                (ulStyle & BS_DEFAULT) ? FIND_OPEN : FIND_CANCEL,
  414.                                BM_SETDEFAULT,
  415.                                MPFROMSHORT(FALSE),0L );
  416.             }
  417.  
  418.         return;
  419.     }
  420. /****************************************************************************/
  421.  
  422.  
  423. /****************************************************************************
  424.  * Directory() - This function is called recursively, successively          *
  425.  *               searching each subdirectory for files that match           *
  426.  *               the search criteria until the entire drive has been        *
  427.  *               traversed.                                                 *
  428.  *                                                                          *
  429.  *               This function returns a value of FALSE if an error         *
  430.  *               occurs, otherwise it returns a value of TRUE.              *
  431.  *                                                                          *
  432.  *               This function uses the scratch data area.                  *
  433.  ****************************************************************************/
  434.     static BOOL near Directory( HWND hwnd,PSZ pszFileSpec,PDATA pData )
  435.     {
  436.         SEL          sel;
  437.         PSZ          pszSpec;
  438.         PSZ          pszSub;
  439.         PFILEFINDBUF pFindbuf;
  440.         HDIR         hdir            = HDIR_CREATE;
  441.         USHORT       usSearchCount   = 1;
  442.         USHORT       usResult,rc;
  443.  
  444.         /*********************************************************
  445.          * Allocate memory for file find buffer                  *
  446.          *   DosAllocSeg is used to keep from overflowing the    *
  447.          *   stack when a disk with a large directory tree is    *
  448.          *   searched.                                           *
  449.          *********************************************************/
  450.         if ( rc = DosAllocSeg(sizeof(FILEFINDBUF),&sel,SEG_NONSHARED) )
  451.             {
  452.             ErrMessageBox( hwnd,szSearchTitle,rc,NULL,0 );
  453.             return FALSE;
  454.             }
  455.         pFindbuf = MAKEP( sel,0 );
  456.  
  457.         /* Split input file spec into directory name and file name */
  458.         strcpy( pData->pszScratch,pszFileSpec );
  459.         pszSpec = strrchr( pszFileSpec,'\\' );
  460.         *pszSpec++ = '\0';
  461.  
  462.         /* Find first file that matches criteria */
  463.         usResult = DosFindFirst( pData->pszScratch,&hdir,pData->usShowAttr,
  464.                                  pFindbuf,sizeof(FILEFINDBUF),
  465.                                  &usSearchCount,0L );
  466.  
  467.         /* Add directory name to list box if a file was found */
  468.         if ( !usResult )
  469.             {
  470.             rc = (SHORT)WinSendDlgItemMsg( hwnd,FIND_FLIST,
  471.                                            LM_INSERTITEM,
  472.                                            MPFROMSHORT(LIT_END),
  473.                                            MPFROMP(pszFileSpec) );
  474.             if ( rc == LIT_MEMERROR || rc == LIT_ERROR )
  475.                 {
  476.                 ErrMessageBox( hwnd,szSearchTitle,LISTBOX_FULL,
  477.                                appMsgList,appMsgCount );
  478.                 DosFreeSeg( SELECTOROF(pFindbuf) );
  479.                 return FALSE;
  480.                 }
  481.             }
  482.  
  483.         /* Add names of found files to list box */
  484.         pData->pszScratch[0] = ' ';
  485.         pData->pszScratch[1] = ' ';
  486.         pData->pszScratch[2] = ' ';
  487.         while ( !usResult )
  488.             {
  489.             strcpy( pData->pszScratch+3,pFindbuf->achName );
  490.             rc = (SHORT)WinSendDlgItemMsg( hwnd,FIND_FLIST,
  491.                                            LM_INSERTITEM,
  492.                                            MPFROMSHORT(LIT_END),
  493.                                            MPFROMP(pData->pszScratch) );
  494.             if ( rc == LIT_MEMERROR || rc == LIT_ERROR )
  495.                 {
  496.                 ErrMessageBox( hwnd,szSearchTitle,LISTBOX_FULL,
  497.                                appMsgList,appMsgCount );
  498.                 DosFreeSeg( SELECTOROF(pFindbuf) );
  499.                 return FALSE;
  500.                 }
  501.             usResult = DosFindNext( hdir,pFindbuf,sizeof(FILEFINDBUF),
  502.                                     &usSearchCount );
  503.             }
  504.         if ( usResult != ERROR_NO_MORE_SEARCH_HANDLES ) DosFindClose(hdir);
  505.         if ( usResult && usResult != ERROR_NO_MORE_FILES )
  506.             {
  507.             ErrMessageBox( hwnd,szSearchTitle,usResult,NULL,0 );
  508.             DosFreeSeg( SELECTOROF(pFindbuf) );
  509.             return FALSE;
  510.             }
  511.  
  512.         /* Allocate memory for subdirectory search spec. */
  513.         if ( rc = DosAllocSeg(pData->usMaxPathLen,&sel,SEG_NONSHARED) )
  514.             {
  515.             ErrMessageBox( hwnd,szSearchTitle,rc,NULL,0 );
  516.             DosFreeSeg( SELECTOROF(pFindbuf) );
  517.             return FALSE;
  518.             }
  519.         pszSub = MAKEP( sel,0 );
  520.  
  521.         /* Search subdirectories for matching files */
  522.         hdir            = HDIR_CREATE;
  523.         usSearchCount   = 1;
  524.         strcpy( pData->pszScratch,pszFileSpec );
  525.         strcat( pData->pszScratch,szSlash );
  526.         strcat( pData->pszScratch,szStarDotStar );
  527.         usResult = DosFindFirst( pData->pszScratch,&hdir,FILE_DIRECTORY,
  528.                                  pFindbuf,sizeof(FILEFINDBUF),
  529.                                  &usSearchCount,0L );
  530.         while ( !usResult )
  531.             {
  532.             if (   (pFindbuf->attrFile & FILE_DIRECTORY)
  533.                 && (pFindbuf->achName[0] != '.') )
  534.                 {
  535.                 strcpy( pszSub,pszFileSpec );
  536.                 strcat( pszSub,szSlash );
  537.                 strcat( pszSub,pFindbuf->achName );
  538.                 strcat( pszSub,szSlash );
  539.                 strcat( pszSub,pszSpec );
  540.                 if ( !Directory(hwnd,pszSub,pData) )
  541.                     {
  542.                     DosFreeSeg( SELECTOROF(pFindbuf) );
  543.                     DosFreeSeg( SELECTOROF(pszSub) );
  544.                     return FALSE;
  545.                     }
  546.                 }
  547.             usResult = DosFindNext( hdir,pFindbuf,sizeof(FILEFINDBUF),
  548.                                     &usSearchCount );
  549.             }
  550.         if ( usResult != ERROR_NO_MORE_SEARCH_HANDLES ) DosFindClose(hdir);
  551.         if ( usResult && usResult != ERROR_NO_MORE_FILES )
  552.             {
  553.             ErrMessageBox( hwnd,szSearchTitle,usResult,NULL,0 );
  554.             DosFreeSeg( SELECTOROF(pFindbuf) );
  555.             DosFreeSeg( SELECTOROF(pszSub) );
  556.             return FALSE;
  557.             }
  558.  
  559.         /* Done. Return to caller */
  560.         DosFreeSeg( SELECTOROF(pFindbuf) );
  561.         DosFreeSeg( SELECTOROF(pszSub) );
  562.         return TRUE;
  563.     }
  564. /****************************************************************************/
  565.  
  566.  
  567. /****************************************************************************
  568.  * OpenFile() - This function attempts to open the file specified           *
  569.  *              in the scratch data area.                                   *
  570.  *                                                                          *
  571.  *              This function returns a non-zero value if an error occured  *
  572.  *              or the input string was a search specification.             *
  573.  ****************************************************************************/
  574.     static USHORT near OpenFile( HWND hDlg,PDATA pData )
  575.     {
  576.         USHORT  usResult;
  577.  
  578.         usResult = ParseFileName( pData->pszScratch,
  579.                                   pData->pszFile,
  580.                                   pData->pszShowSpec );
  581.         if ( usResult )
  582.             {
  583.             ErrMessageBox( hDlg,pData->pszTitle,usResult,NULL,0 );
  584.             return 1;
  585.             }
  586.  
  587.         if ( NULL != strpbrk(pData->pszFile,szWildCardChars) )
  588.             return 1;
  589.         else
  590.             {
  591.             usResult = DosOpen( pData->pszFile,
  592.                                 pData->phf,
  593.                                 pData->pusAction,
  594.                                 pData->ulFileSize,
  595.                                 pData->usAttribute,
  596.                                 pData->fsOpenFlags,
  597.                                 pData->fsOpenMode,
  598.                                 pData->ulReserved );
  599.             if ( usResult )
  600.                 {
  601.                 ErrMessageBox( hDlg,pData->pszTitle,usResult,NULL,0 );
  602.                 return 1;
  603.                 }
  604.             else
  605.                 return 0;
  606.             }
  607.     }
  608. /****************************************************************************/
  609.