home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bmp4.zip / OPENDLG.C < prev    next >
C/C++ Source or Header  |  1995-11-06  |  22KB  |  625 lines

  1. #pragma    title("Pointer Creation Tool  --  Version 1  --  (OpenDlg.C)")
  2. #pragma    subtitle("   File Open - Interface Definitions")
  3.  
  4. #define    INCL_DOS           /* Include OS/2 DOS Kernal        */
  5. #define    INCL_DOSERRORS           /* Include OS/2 DOS Errors        */
  6. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  7. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  8.  
  9. #pragma    info(noext)
  10.  
  11. #include <malloc.h>
  12. #include <os2.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #include "appdefs.h"
  18. #include "makeptr.h"
  19.  
  20. /* This    module contains    the routines that allow    the user to select a    */
  21. /* bitmap file to open and view.                    */
  22.  
  23. /* Filename:   OpenDlg.C                        */
  24.  
  25. /*  Version:   1                            */
  26. /*  Created:   1995-11-06                        */
  27. /*  Revised:   1995-11-06                        */
  28.  
  29. /* Routines:   MRESULT EXPENTRY    OpenDlgProc(HWND hWnd, ULONG msg,    */
  30. /*                        MPARAM mp1,    MPARAM mp2);    */
  31. /*           static VOID ShowDirInfo(HWND hWnd, ULONG    idPath,        */
  32. /*                       ULONG idVol, ULONG idRoom);    */
  33. /*           static VOID DiskVolDrive(ULONG ulDrive,            */
  34. /*                    CHAR *pszDiskName);        */
  35. /*           static VOID QueryDriveList( );                */
  36. /*           static ULONG ulGetDirList(HWND hwndDrives, HWND hwndDirs,*/
  37. /*                     HWND hwndFiles);        */
  38.  
  39. /************************************************************************/
  40. /************************************************************************/
  41. /************************************************************************/
  42. /* DISCLAIMER OF WARRANTIES:                        */
  43. /* -------------------------                        */
  44. /* The following [enclosed] code is sample code    created    by IBM        */
  45. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  46. /* standard IBM    product    and is provided    to you solely for the purpose    */
  47. /* of assisting    you in the development of your applications.  The code    */
  48. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  49. /* Prominare shall be liable for any damages arising out of your    */
  50. /* use of the sample code, even    if they    have been advised of the    */
  51. /* possibility of such damages.                        */
  52. /************************************************************************/
  53. /************************************************************************/
  54. /************************************************************************/
  55. /*               D I S C L A I M E R                */
  56. /* This    code is    provided on an as is basis with    no implied support.    */
  57. /* It should be    considered freeware that cannot    be rebundled as        */
  58. /* part    of a larger "*ware" offering without our consent.        */
  59. /************************************************************************/
  60. /************************************************************************/
  61. /************************************************************************/
  62.  
  63. /* Copyright ╕ International Business Machines Corp., 1995.        */
  64. /* Copyright ╕ 1995  Prominare Inc.  All Rights    Reserved.        */
  65.  
  66. /* --------------------------------------------------------------------    */
  67.  
  68. /************************************************************************/
  69. /*                                    */
  70. /*     Module Prototype    Definitions                    */
  71. /*                                    */
  72. /************************************************************************/
  73.  
  74. static VOID  QueryDriveList(VOID);
  75. static ULONG ulGetDirList(HWND hwndDrives, HWND    hwndDirs, HWND hwndFiles);
  76. static VOID  DiskVolDrive(ULONG    ulDrive, CHAR *pszDiskName);
  77. static VOID  ShowDirInfo(HWND hWnd, ULONG idPath, ULONG    idVol, ULONG idRoom);
  78.  
  79. /************************************************************************/
  80. /*                                    */
  81. /*     Module Data Definitions                        */
  82. /*                                    */
  83. /************************************************************************/
  84.  
  85. BOOL  fLineNumbers = FALSE;       /* Line Numbers Flag            */
  86. INT   iFileSel = LIT_NONE;       /* File Selected            */
  87. BOOL  fDrivesFilled;           /* Drives Filled Flag        */
  88. ULONG ulDriveMap;           /* Drive Bit    Map Holder        */
  89. LONG  cDrives;
  90. CHAR  aszDrives[26][20];
  91. BOOL  afRemoveable[26] = { FALSE, FALSE, FALSE,    FALSE, FALSE, FALSE, FALSE, FALSE,
  92.                FALSE, FALSE, FALSE,    FALSE, FALSE, FALSE, FALSE, FALSE,
  93.                FALSE, FALSE, FALSE,    FALSE, FALSE, FALSE, FALSE, FALSE,
  94.                FALSE, FALSE    };
  95.  
  96. #pragma    subtitle("   Open Bitmap -  Open Bitmap Dialogue Procedure")
  97. #pragma    page( )
  98.  
  99. /* --- OpenDlgProc ------------------------------------- [ Public ] ---    */
  100. /*                                    */
  101. /*     This function is    used to    retrieve a bitmap file for viewing    */
  102. /*     print dialogue procedure.                    */
  103. /*                                    */
  104. /*     Upon Entry:                            */
  105. /*                                    */
  106. /*     HWND   hWnd; = Dialog Window Handle                */
  107. /*     ULONG  msg;  = PM Message                    */
  108. /*     MPARAM mp1;  = Message Parameter    1                */
  109. /*     MPARAM mp2;  = Message Parameter    2                */
  110. /*                                    */
  111. /*     Upon Exit:                            */
  112. /*                                    */
  113. /*     OpenDlgProc = Message Handling Result                */
  114. /*                                    */
  115. /* --------------------------------------------------------------------    */
  116.  
  117. MRESULT    EXPENTRY OpenDlgProc(HWND hWnd,    ULONG msg, MPARAM mp1, MPARAM mp2)
  118.  
  119. {
  120. CHAR     szFileName[CCHMAXPATH];   /* Filename Holder            */
  121. CHAR     szStrBuf[CCHMAXPATH];       /* String Buffer            */
  122. register INT i;               /* Loop Counters            */
  123.  
  124. switch ( msg )
  125.    {
  126.                /* Perform dialog initialization            */
  127.    case    WM_INITDLG :
  128.        WinSetPointer(HWND_DESKTOP, hptrWait);
  129.  
  130.                /* Clear    the drives filled flag            */
  131.  
  132.        fDrivesFilled = FALSE;
  133.  
  134.                /* Get a    list of    the drives, directories    and    */
  135.                /* files    for the    list boxes and show the    number    */
  136.                /* of files within the directory            */
  137.  
  138.        sprintf(szStrBuf, "%d", ulGetDirList(WinWindowFromID(hWnd, CBX_DRIVES),
  139.                         WinWindowFromID(hWnd, LB_DIRECTORIES),
  140.                         WinWindowFromID(hWnd, LB_FILES)));
  141.        WinSetDlgItemText(hWnd, IT_FILECOUNT, szStrBuf);
  142.  
  143.                /* Get directory/file list and display in list    */
  144.                /* boxes                        */
  145.  
  146.        ShowDirInfo(hWnd, IT_DIRECTORY, IT_VOLUMELABEL, IT_DISKFREE);
  147.  
  148.                /* Select the last Open Bitmaped             */
  149.  
  150.        if ( iFileSel !=    LIT_NONE )
  151.        WinSendDlgItemMsg(hWnd, LB_DIRECTORIES, LM_SELECTITEM, MPFROMSHORT(iFileSel),
  152.                  MPFROMSHORT(TRUE));
  153.        WinSetPointer(HWND_DESKTOP, hptrArrow);
  154.        break;
  155.             /* Process control selections            */
  156.    case    WM_CONTROL :
  157.        switch (    SHORT2FROMMP(mp1) )
  158.        {
  159.                /* Enter    or selection made within error combo    */
  160.                /* box                        */
  161.        case    CBN_ENTER :
  162.            switch (    SHORT1FROMMP(mp1) )
  163.            {
  164.            case    CBX_DRIVES :
  165.  
  166.                /* Get item selected from the list box        */
  167.  
  168.                WinSendDlgItemMsg(hWnd, CBX_DRIVES, LM_QUERYITEMTEXT,
  169.                   MPFROM2SHORT(LONGFROMMR(WinSendDlgItemMsg(hWnd, CBX_DRIVES,
  170.                                         LM_QUERYSELECTION,
  171.                                         0L,    0L)),
  172.                            CCHMAXPATH),
  173.                   MPFROMP(szFileName));
  174.  
  175.                /* Change drives                    */
  176.  
  177.                DosSetDefaultDisk((ULONG)((szFileName[0]    & 223) - '@'));
  178.  
  179.                /* Refresh the directory    files list and show the    */
  180.                /* number of files within the directory        */
  181.  
  182.                sprintf(szStrBuf, "%d", ulGetDirList(WinWindowFromID(hWnd, CBX_DRIVES),
  183.                     WinWindowFromID(hWnd, LB_DIRECTORIES),
  184.                     WinWindowFromID(hWnd, LB_FILES)));
  185.                WinSetDlgItemText(hWnd, IT_FILECOUNT, szStrBuf);
  186.  
  187.                /* Display the directory    path, volume label and    */
  188.                /* total    disk space free                */
  189.  
  190.                ShowDirInfo(hWnd, IT_DIRECTORY, IT_VOLUMELABEL, IT_DISKFREE);
  191.                break;
  192.  
  193.            default :
  194.                break;
  195.            }
  196.            break;
  197.                /* Drive/directory selected, get    entry selected    */
  198.                /* and change to    drive or directory selected    */
  199.  
  200.        case    LN_ENTER :
  201.            switch (    SHORT1FROMMP(mp1) )
  202.            {
  203.            case    LB_DIRECTORIES :
  204.  
  205.                /* Get item selected from the directories list    */
  206.                /* box                        */
  207.  
  208.                WinSendDlgItemMsg(hWnd, LB_DIRECTORIES, LM_QUERYITEMTEXT,
  209.                   MPFROM2SHORT(LONGFROMMR(WinSendDlgItemMsg(hWnd, LB_DIRECTORIES,
  210.                                         LM_QUERYSELECTION, 0L, 0L)),
  211.                            sizeof(szFileName)),
  212.                   MPFROMP(szFileName));
  213.  
  214.                /* Change to the    selected directory        */
  215.  
  216.                DosSetCurrentDir(szFileName);
  217.  
  218.                /* Refresh the directory    files list and show the    */
  219.                /* number of files within the directory        */
  220.  
  221.                sprintf(szStrBuf, "%d", ulGetDirList(WinWindowFromID(hWnd, CBX_DRIVES),
  222.                     WinWindowFromID(hWnd, LB_DIRECTORIES),
  223.                     WinWindowFromID(hWnd, LB_FILES)));
  224.                WinSetDlgItemText(hWnd, IT_FILECOUNT, szStrBuf);
  225.  
  226.                /* Display the directory    path, volume label and    */
  227.                /* total    disk space free                */
  228.  
  229.                ShowDirInfo(hWnd, IT_DIRECTORY, IT_VOLUMELABEL, IT_DISKFREE);
  230.                break;
  231.  
  232.            case    LB_FILES :
  233.  
  234.                /* Item within the files    list box double    clicked    */
  235.                /* on, user indicating that the file selected    */
  236.                /* should be printed, therefore,    force the    */
  237.                /* simulation of    the Print push button        */
  238.  
  239.                WinSendMsg(hWnd,    WM_COMMAND, MPFROMSHORT(DID_OK), 0L);
  240.                break;
  241.            }
  242.            break;
  243.        }
  244.        break;
  245.             /* Process push    button selections        */
  246.    case    WM_COMMAND :
  247.     switch ( SHORT1FROMMP(mp1) )
  248.         {
  249.                /* Print    push button clicked            */
  250.        case    DID_OK :
  251.                /* Get the file selected                */
  252.  
  253.            if ( (iFileSel =    (i = (INT)LONGFROMMR(WinSendDlgItemMsg(hWnd, LB_FILES,
  254.                                        LM_QUERYSELECTION,
  255.                                        0L, 0L)))) == LIT_NONE )
  256.            break;
  257.            else
  258.                /* Get item selected from the list box and    */
  259.                /* determine which file selected            */
  260.  
  261.            WinSendDlgItemMsg(hWnd, LB_FILES, LM_QUERYITEMTEXT, MPFROM2SHORT(i, CCHMAXPATH), MPFROMP(szBitmapFile));
  262.  
  263.            WinDismissDlg(hWnd, TRUE);
  264.            break;
  265.                /* Cancel push button selected            */
  266.        case    DID_CANCEL :
  267.            WinDismissDlg(hWnd, FALSE);
  268.            break;
  269.         }
  270.     break;
  271.             /* Close requested, exit dialogue        */
  272.    case    WM_CLOSE :
  273.     WinDismissDlg(hWnd, FALSE);
  274.     break;
  275.             /* Pass    through    unhandled messages        */
  276.    default :
  277.        return(WinDefDlgProc(hWnd, msg, mp1, mp2));
  278.    }
  279. return(0L);
  280. }
  281. #pragma    subtitle("   Open Bitmap - Directory Information Display Function")
  282. #pragma    page( )
  283.  
  284. /* --- ShowDirInfo ------------------------------------    [ Private ] ---    */
  285. /*                                    */
  286. /*     This function is    used to    display    information regarding the    */
  287. /*     path, volume label and room remaining.                */
  288. /*                                    */
  289. /*     Upon Entry:                            */
  290. /*                                    */
  291. /*     HWND  hWnd;   = Dialog Dialogue Window Handle            */
  292. /*     ULONG idPath; = Path ID                        */
  293. /*     ULONG idVol;  = Volume Label ID                    */
  294. /*     ULONG idRoom; = Room Remaining ID                */
  295. /*                                    */
  296. /*     Upon Exit:                            */
  297. /*                                    */
  298. /*     Nothing                                */
  299. /*                                    */
  300. /* --------------------------------------------------------------------    */
  301.  
  302. static VOID ShowDirInfo(HWND hWnd, ULONG idPath, ULONG idVol, ULONG idRoom)
  303.  
  304. {
  305. CHAR       szStrBuf[CCHMAXPATH];   /* String Buffer            */
  306. FSALLOCATE diskinfo;           /* Disk Information Structure    */
  307. FSINFO       fsinf;           /* Disk Volume Information Structure    */
  308. ULONG       cbBuf;           /* Directory    Buffer Size Count    */
  309. ULONG       ulCurDrive;           /* Current Drive Designation        */
  310. ULONG       ulDrives;           /* Drive Map                */
  311.  
  312.                /* Form the current drive/path and display    */
  313.                /* within the Path display field            */
  314.  
  315. DosQueryCurrentDisk(&ulCurDrive, &ulDriveMap);
  316.  
  317.                /* Get the current drive    and path being used and    */
  318.                /* display with Path display field        */
  319.  
  320. DosQueryCurrentDisk(&ulCurDrive, &ulDrives);
  321. memcpy(&szStrBuf[1], ":\\", 3);
  322. szStrBuf[0] = (CHAR)(ulCurDrive    + '@');
  323. cbBuf =    CCHMAXPATH - 3;
  324.                /* Get information on the current directory    */
  325.  
  326. if ( !DosQueryCurrentDir(ulCurDrive, &szStrBuf[3], &cbBuf) )
  327.    {
  328.                /* Show the full    path information        */
  329.  
  330.    WinSetDlgItemText(hWnd, idPath, szStrBuf);
  331.  
  332.                /* Get the volume information and display it    */
  333.  
  334.    if (    !DosQueryFSInfo(0UL, FSIL_VOLSER, (PBYTE)(&fsinf), sizeof(FSINFO)) )
  335.        if ( fsinf.vol.szVolLabel[0] )
  336.        WinSetDlgItemText(hWnd, idVol, fsinf.vol.szVolLabel);
  337.        else
  338.        WinSetDlgItemText(hWnd, idVol, "");
  339.  
  340.                /* Get the remaining space of the drive and    */
  341.                /* display                    */
  342.  
  343.    if (    !DosQueryFSInfo(ulCurDrive, FSIL_ALLOC,    (PVOID)&diskinfo, sizeof(FSALLOCATE)) )
  344.        WinSetDlgItemText(hWnd, idRoom,
  345.              strcat(_ltoa((LONG)(diskinfo.cbSector * diskinfo.cSectorUnit *    diskinfo.cUnitAvail),
  346.                 szStrBuf, 10), " Bytes"));
  347.    }
  348. }
  349. #pragma    subtitle("   Open Bitmap - Get Disk Volume Label Function")
  350. #pragma    page( )
  351.  
  352. /* --- DiskVolDrive -----------------------------------    [ Private ] ---    */
  353. /*                                    */
  354. /*     This function is    used to    retrieve the volume label of the    */
  355. /*     default disk drive.                        */
  356. /*                                    */
  357. /*     Upon Entry:                            */
  358. /*                                    */
  359. /*     ULONG ulDrive;       = Drive Number                */
  360. /*     CHAR  *pszDiskName; = Holder for    Volume Label            */
  361. /*                                    */
  362. /*     Upon Exit:                            */
  363. /*                                    */
  364. /*     Nothing                                */
  365. /*                                    */
  366. /* --------------------------------------------------------------------    */
  367.  
  368. static VOID DiskVolDrive(ULONG ulDrive,    CHAR *pszDiskName)
  369.  
  370. {
  371. FSINFO fsinf;              /* Disk Volume Information Structure */
  372.  
  373.                /* Get the disk volume label            */
  374.  
  375. if ( !DosQueryFSInfo(ulDrive, FSIL_VOLSER, (PBYTE)(&fsinf), sizeof(FSINFO)) )
  376.    if (    fsinf.vol.szVolLabel[0]    )
  377.        strcat(strcat(memcpy(pszDiskName, "[ ", 3), fsinf.vol.szVolLabel), " ]");
  378.    else
  379.        pszDiskName[0] =    (CHAR)0;
  380. }
  381. #pragma    subtitle("   Open Bitmap - Drive List Query Procedure")
  382. #pragma    page( )
  383.  
  384. /* --- QueryDriveList ---------------------------------- [ Public ] ---    */
  385. /*                                    */
  386. /*     This function is    used to    build a    list of    valid drives.        */
  387. /*                                    */
  388. /*     Upon Entry:                            */
  389. /*                                    */
  390. /*     Nothing                                */
  391. /*                                    */
  392. /*     Upon Exit:                            */
  393. /*                                    */
  394. /*     Nothing                                */
  395. /*                                    */
  396. /* --------------------------------------------------------------------    */
  397.  
  398. static VOID QueryDriveList(VOID)
  399.  
  400. {
  401. CHAR        szDrive[4];           /* Drive Designation    Holder        */
  402. PFSQBUFFER2 psqbf;           /* File System Query    Buffer Pointer    */
  403. ULONG        cbDrvi;           /* Buffer Count            */
  404. ULONG        ulError;           /* OS/2 Error            */
  405. ULONG        ulCurDrive;           /* Current Drive Designation        */
  406. ULONG        ulDriveMask    = 1;       /* Drive Bit    Map Mask        */
  407. register INT i;               /* Loop Counter            */
  408.  
  409.                /* Perform general initialization        */
  410.  
  411. DosQueryCurrentDisk(&ulCurDrive, &ulDriveMap);
  412.  
  413.                /* Allocate space for the file system query    */
  414.                /* buffer                    */
  415.  
  416. psqbf =    (PFSQBUFFER2)malloc(1024UL);
  417. memcpy(&szDrive[1], ":", 2);
  418. DosError(FERR_DISABLEHARDERR);
  419.  
  420. for ( i    = cDrives = 0; i < 26; i++ )
  421.    {
  422.                /* Determine if a disk drive present by masking    */
  423.                /* out the drive    present    bit            */
  424.  
  425.    if (    ulDriveMap & ulDriveMask )
  426.        {
  427.                /* Save the drive designation for the drive    */
  428.                /* that is present                */
  429.  
  430.        aszDrives[cDrives][0] = szDrive[0] = (CHAR)(i + 'A');
  431.        memcpy(&aszDrives[cDrives][1], ":\\ ", 4);
  432.  
  433.                /* Start    with hard disk drives, check to    see if    */
  434.                /* the drive is local or    remote.     Remote    drives    */
  435.                /* are generally    networked drives.  Prominare    */
  436.                /* Builder denotes diskette, local and remote    */
  437.                /* drives within    the Drives/Directories window.    */
  438.        if ( i >    1 )
  439.        {
  440.                /* Initialize the buffer    count before the file    */
  441.                /* system is queried otherwise the call may fail    */
  442.  
  443.        cbDrvi = 1024UL;
  444.  
  445.        if (    (ulError = DosQueryFSAttach(szDrive, 1UL, FSAIL_QUERYNAME, (PFSQBUFFER2)psqbf, &cbDrvi)) == ERROR_NOT_READY )
  446.            afRemoveable[cDrives++] = TRUE;
  447.        else
  448.            if ( !ulError )
  449.            if (    !memcmp(&psqbf->rgFSAData[1], "CDFS", 5) )
  450.                afRemoveable[cDrives++] = TRUE;
  451.            else
  452.                ++cDrives;
  453.        }
  454.        else
  455.        afRemoveable[cDrives++] = TRUE;
  456.        }
  457.                /* Shift    the drive designation bitmap mask    */
  458.    ulDriveMask <<= 1;
  459.    }
  460. DosError(FERR_ENABLEHARDERR);
  461.  
  462.                /* Release the memory allocated for the query    */
  463.                /* buffer                    */
  464. free(psqbf);
  465. }
  466. #pragma    subtitle("   Open Bitmap - Directory Retrieval/Display Function")
  467. #pragma    page( )
  468.  
  469. /* --- ulGetDirList -----------------------------------    [ Private ] ---    */
  470. /*                                    */
  471. /*     This function is    used to    search for sub-directories and files    */
  472. /*     within the current sub-directory/drive and place    the entries    */
  473. /*     within two list boxes.                        */
  474. /*                                    */
  475. /*     Upon Entry:                            */
  476. /*                                    */
  477. /*     HWND hwndDrives;    = Drives Combo Box Handle            */
  478. /*     HWND hwndDirs;    = Directories List Box Handle            */
  479. /*     HWND hwndFiles;    = Files    List Box Handle                */
  480. /*                                    */
  481. /*     Upon Exit:                            */
  482. /*                                    */
  483. /*     ulGetDirList = Number of    Files in Files List Box            */
  484. /*                                    */
  485. /* --------------------------------------------------------------------    */
  486.  
  487. static ULONG ulGetDirList(HWND hwndDrives, HWND    hwndDirs, HWND hwndFiles)
  488.  
  489. {
  490. HDIR          hDir = (HDIR)HDIR_CREATE;/* Directory Handle        */
  491. HPOINTER      hptr;           /* Mouse Pointer Handle        */
  492. PFILEFINDBUF3 pfindbuf3;       /* File Find    Buffer            */
  493. PFILEFINDBUF3 pfindbuf;           /* File Find    Buffer            */
  494. ULONG          cFiles = 0UL;       /* Files Count            */
  495. ULONG          ulCurDrive;       /* Current Drive Designation        */
  496. ULONG          ulDrives;           /* Drive Bit    Map Holder        */
  497. ULONG          ulErr;           /* OS/2 Error Value            */
  498. ULONG          ulFileCnt    = 71UL;       /* File Counter Holder        */
  499. register INT i,    n;           /* Loop Counters            */
  500.  
  501. hptr = WinQueryPointer(HWND_DESKTOP);
  502.  
  503.                /* Set the mouse    pointer    to hourglass shape    */
  504.                /* while    directory search taking    place        */
  505.  
  506. WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT,    FALSE));
  507.  
  508.                /* Allocate memory for a    large directory    search    */
  509.                /* buffer                    */
  510.  
  511. pfindbuf3 = (PFILEFINDBUF3)malloc(71UL * sizeof(FILEFINDBUF3));
  512.  
  513.                /* Get the handles of the list boxes and    disable    */
  514.                /* updating of them while inserting the data    */
  515.                /* into them and    delete the contents within them    */
  516.  
  517. WinEnableWindowUpdate(hwndDirs,     FALSE);
  518. WinEnableWindowUpdate(hwndFiles, FALSE);
  519. WinSendMsg(hwndDirs,  LM_DELETEALL, 0L,    0L);
  520. WinSendMsg(hwndFiles, LM_DELETEALL, 0L,    0L);
  521.  
  522.                /* Start    directory search            */
  523.  
  524. if ( !(ulErr = DosFindFirst("*.*", &hDir, MUST_HAVE_DIRECTORY |    FILE_DIRECTORY,
  525.                 (PVOID)pfindbuf3, 71UL * sizeof(FILEFINDBUF3), &ulFileCnt, FIL_STANDARD)) )
  526.    {
  527.    do
  528.        for ( i = 0, pfindbuf = pfindbuf3; i < ulFileCnt; i++ )
  529.        {
  530.                /* If file found    a sub-directory, place into the    */
  531.                /* Directories list box                */
  532.  
  533.        if (    (pfindbuf->attrFile & FILE_DIRECTORY) && memcmp(pfindbuf->achName, ".",    2) )
  534.            WinSendMsg(hwndDirs, LM_INSERTITEM, MPFROMSHORT(LIT_SORTASCENDING), MPFROMP(pfindbuf->achName));
  535.        pfindbuf = (PFILEFINDBUF3)((PBYTE)pfindbuf +    pfindbuf->oNextEntryOffset);
  536.        }
  537.        while ( (ulFileCnt == 71UL) && !DosFindNext(hDir, pfindbuf3, 71UL * sizeof(FILEFINDBUF3), &ulFileCnt) );
  538.  
  539.                /* Close    directory search handle            */
  540.    DosFindClose(hDir);
  541.    }
  542. else
  543.    if (    ulErr != ERROR_NO_MORE_FILES )
  544.        {
  545.                /* Release the memory allocated for the search    */
  546.                /* buffer                    */
  547.  
  548.        free((PVOID)pfindbuf3);
  549.        return(0);
  550.        }
  551.  
  552. if ( !fDrivesFilled )
  553.    {
  554.                /* Form the current drive/path and display    */
  555.                /* within the Path display field            */
  556.  
  557.    DosQueryCurrentDisk(&ulCurDrive, &ulDrives);
  558.    if (    ulDriveMap != ulDrives )
  559.        QueryDriveList( );
  560.    for ( i = 0;    i < cDrives; i++ )
  561.        {
  562.        if ( !afRemoveable[i] )
  563.        DiskVolDrive((ULONG)(i + 1),    &aszDrives[i][4]);
  564.        else
  565.        aszDrives[i][4] = (CHAR)0;
  566.        n = (INT)LONGFROMMR(WinSendMsg(hwndDrives, LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(aszDrives[i])));
  567.        if ( i == (ulCurDrive - 1) )
  568.        WinSendMsg(hwndDrives, LM_SELECTITEM, MPFROMLONG(n),    MPFROMLONG(TRUE));
  569.        }
  570.    fDrivesFilled = TRUE;
  571.    }
  572.                /* Reset    directory handle and file counter    */
  573. hDir = (HDIR)HDIR_CREATE;
  574. ulFileCnt = 71UL;
  575.                /* Start    file search                */
  576.  
  577. if ( !(ulErr = DosFindFirst("*.bmp", &hDir, FILE_NORMAL, (PVOID)pfindbuf3, 71UL    * sizeof(FILEFINDBUF3),    &ulFileCnt, FIL_STANDARD)) )
  578.    {
  579.    do
  580.        for ( i = 0, pfindbuf = pfindbuf3; i < ulFileCnt; i++ )
  581.        {
  582.                /* If file found    not a sub-directory, place    */
  583.                /* filename in list box                */
  584.  
  585.        if (    (pfindbuf->attrFile & FILE_DIRECTORY) != FILE_DIRECTORY    )
  586.            {
  587.            ++cFiles;
  588.            WinSendMsg(hwndFiles, LM_INSERTITEM, MPFROMSHORT(LIT_SORTASCENDING), MPFROMP(pfindbuf->achName));
  589.            }
  590.        pfindbuf = (PFILEFINDBUF3)((PBYTE)pfindbuf +    pfindbuf->oNextEntryOffset);
  591.        }
  592.                /* Search for remaining entries and place valid    */
  593.                /* entries in list box                */
  594.  
  595.        while ( (ulFileCnt == 71UL) && !DosFindNext(hDir, pfindbuf3, 71UL * sizeof(FILEFINDBUF3), &ulFileCnt) );
  596.  
  597.                /* Close    directory search handle            */
  598.    DosFindClose(hDir);
  599.    }
  600. else
  601.    if (    ulErr != ERROR_NO_MORE_FILES )
  602.        {
  603.                /* Release the memory allocated for the search    */
  604.                /* buffer                    */
  605.  
  606.        free((PVOID)pfindbuf3);
  607.        return(0);
  608.        }
  609.                /* Release the memory allocated for the search    */
  610.                /* buffer                    */
  611. free((PVOID)pfindbuf3);
  612.                /* Re-enable updating to    the list boxes and    */
  613.                /* force    the displaying of the new contents    */
  614.  
  615. WinShowWindow(hwndDirs,    TRUE);
  616. WinShowWindow(hwndFiles, TRUE);
  617.  
  618.                /* Reset    edit field text    in case    invalid    search    */
  619.                /* spec entered and reset mouse pointer back to    */
  620.                /* arrow    shape                    */
  621.  
  622. WinSetPointer(HWND_DESKTOP, hptr);
  623. return(cFiles);
  624. }
  625.