home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / opendlg / file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-20  |  19.7 KB  |  633 lines

  1. /*
  2.     FILE.C -- Open/Save As Dialog Box library routines
  3.     Created by Microsoft Corporation, 1989
  4. */
  5. #define  INCL_DOS
  6. #define  INCL_DOSQUEUES
  7. #include "tool.h"
  8.  
  9.  
  10. /****************************************************************************\
  11. * This function is the Open dialog box window procedure.  It handles input,
  12. * allows the user to change directories, checks for legal filenames, opens
  13. * specified files, appends default extensions and returns the file's name.
  14. *
  15. * The return values are
  16. *   TDF_INVALID - Library error (internal error),
  17. *   TDF_NOOPEN  - User hits cancel
  18. *   TDF_NEWOPEN - Created new file (file left open)
  19. *   TDF_OLDOPEN - Opened existing file (file left open)
  20. \****************************************************************************/
  21.  
  22. MRESULT EXPENTRY DlgOpenWndProc(hwnd, msg, mp1, mp2)
  23. HWND hwnd;
  24. USHORT msg;
  25. MPARAM mp1;
  26. MPARAM mp2;
  27.     {
  28.     PDLF pdlf;
  29.     PSZ  lpchFile;
  30.     CHAR sz[MAX_FNAME_LEN];
  31.  
  32.     switch (msg)
  33.         {
  34.     case WM_INITDLG:
  35.         /* initialize dialog box */
  36.         DlgInitOpen(hwnd, LONGFROMMP(mp2));
  37.  
  38.         /* fill static field with path name and fill list box with
  39.            filenames that lMatch spec */
  40.         if (!DlgDirList(hwnd, ((PDLF)(mp2))->pszExt+1, ID_DIRLIST,
  41.                         ID_FILELIST, ID_PATH, ((PDLF)(mp2))->rgbFlags))
  42.             /* NOTE: shouldn't we post a message if something screws up? */
  43.             WinDismissDlg(hwnd, TDF_INVALID);
  44.         break;
  45.  
  46.     case WM_COMMAND:
  47.         pdlf = (PDLF) WinQueryWindowULong(hwnd, 0);
  48.         switch (SHORT1FROMMP(mp1))
  49.             {
  50.         case MBID_OK:
  51.             /* Open button pressed */
  52.             /* get name from edit box */
  53.             WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
  54.                 CBROOTNAMEMAX, (PSZ)pdlf->szFileName);
  55.         Upper((PSZ)pdlf->szFileName);
  56.             if (lstrlen((PSZ)pdlf->szFileName))
  57.                 DlgOpenName(hwnd, pdlf);
  58.             break;
  59.  
  60.         case MBID_CANCEL:
  61.             /* Cancel button pressed, dismiss dialog box */
  62.             WinDismissDlg(hwnd, TDF_NOOPEN);
  63.         break;
  64.  
  65.     case MBID_HELP:
  66.         /* Help button pressed */
  67.         WinMessageBox( HWND_DESKTOP
  68.              , hwnd
  69.              , pdlf->pszInstructions
  70.              , pdlf->pszTitle
  71.              , NULL
  72.              , MB_OK | MB_APPLMODAL );
  73.         break;
  74.             }
  75.         break;
  76.  
  77.     case WM_CONTROL:
  78.         pdlf = (PDLF) WinQueryWindowULong(hwnd, 0);
  79.         switch (SHORT1FROMMP(mp1))
  80.             {
  81.         case ID_DIRLIST:
  82.             /* user clicked in directory list box */
  83.             switch (SHORT2FROMMP(mp1))
  84.                 {
  85.             case LN_SELECT:
  86.                 /* single click case */
  87.                 /* get current edit string */
  88.                 WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
  89.                                    CBROOTNAMEMAX, (PSZ)sz);
  90.                 Upper((PSZ)sz);
  91.  
  92.                 /* get selected string */
  93.                 if (DlgDirSelect(hwnd, (PSZ)pdlf->szFileName, ID_DIRLIST))
  94.                     {
  95.                     /* if edit field contains wild card, then append file
  96.                part to selected directory, otherwise append
  97.                last wildcard search spec */
  98.                     lpchFile = FileInPath((PSZ)sz);
  99.             lstrcat( (PSZ)pdlf->szFileName
  100.                , DlgSearchSpec( lpchFile)
  101.                  ? lpchFile
  102.                  : (PSZ)pdlf->szLastWild );
  103.                     /* set edit box to resulting name */
  104.                     WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
  105.                                      (PSZ)pdlf->szFileName);
  106.                     }
  107.                 break;
  108.  
  109.             case LN_ENTER:
  110.         /* get text from edit box */
  111.         WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
  112.                    CBROOTNAMEMAX, (PSZ)pdlf->szFileName);
  113.         Upper((PSZ)pdlf->szFileName);
  114.         if( DlgSearchSpec( (PSZ)pdlf->szFileName))
  115.             {
  116.             DlgDirList( hwnd
  117.                   , (PSZ)pdlf->szFileName
  118.                   , ID_DIRLIST
  119.                   , ID_FILELIST
  120.                   , ID_PATH
  121.                   , pdlf->rgbFlags );
  122.             lstrcpy( (PSZ)pdlf->szLastWild
  123.                , FileInPath( (PSZ)pdlf->szFileName));
  124.             WinSetWindowText( WinWindowFromID( hwnd, ID_EDIT)
  125.                     , (PSZ)pdlf->szFileName );
  126.             }
  127.                 break;
  128.                 }
  129.             break;
  130.  
  131.         case ID_FILELIST:
  132.             /* user clicked in file list box */
  133.             switch (SHORT2FROMMP(mp1))
  134.                 {
  135.             case LN_SELECT:
  136.                 /* single click case */
  137.  
  138.         /* get current edit string */
  139.         /* if it contains a wildcard, save it before obliteration */
  140.                 WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
  141.                                    CBROOTNAMEMAX, (PSZ)sz);
  142.         Upper((PSZ)sz);
  143.         if( DlgSearchSpec( (PSZ)sz))
  144.             lstrcpy( (PSZ)pdlf->szLastWild, FileInPath( (PSZ)sz));
  145.  
  146.                 /* get selected file name */
  147.                 DlgDirSelect(hwnd, (PSZ)pdlf->szFileName, ID_FILELIST);
  148.                 /* set edit box to resulting name */
  149.                 WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
  150.                                  (PSZ)pdlf->szFileName);
  151.                 break;
  152.  
  153.             case LN_ENTER:
  154.                 /* double click case, single click already processed */
  155.                 DlgOpenName(hwnd, pdlf);
  156.                 break;
  157.                 }
  158.             break;
  159.             }
  160.         break;
  161.  
  162.     default:
  163.         return (WinDefDlgProc(hwnd, msg, mp1, mp2));
  164.         }
  165.  
  166.     return (MRFROMLONG(0L));  /* message processed */
  167.     }
  168.  
  169.  
  170.  
  171.  
  172. /****************************************************************************\
  173. * This function stores the pdlf in the dialog window structure, sets
  174. * the title and instruction texts and limits the text size.
  175. \****************************************************************************/
  176.  
  177. VOID PASCAL DlgInitOpen (hwnd, lpParm)
  178. HWND hwnd;
  179. ULONG lpParm;
  180.     {
  181.     PDLF pdlf;
  182.  
  183.     /* Set pdlf local to window */
  184.     pdlf = (PDLF) lpParm;
  185.     WinSetWindowULong(hwnd, 0, lpParm);
  186.  
  187.     /* set edit box text size limit */
  188.     WinSendDlgItemMsg(hwnd, ID_EDIT, EM_SETTEXTLIMIT, (MPARAM)CBROOTNAMEMAX, 0L);
  189.  
  190.     /* set edit window to search spec */
  191.     if (pdlf->pszExt != (PSZ)NULL)
  192.         WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT), pdlf->pszExt+1);
  193.  
  194.     /* set title window */
  195.     if (pdlf->pszTitle != (PSZ)NULL)
  196.     WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), pdlf->pszTitle);
  197.     }
  198.  
  199.  
  200.  
  201.  
  202. /****************************************************************************\
  203. * This function processes the currently selected name in the open dialog
  204. * box.  If the name represents a directory, the current directory is
  205. * changed to that one and the corresponding files are displayed.  If the
  206. * name is a file, then it is opened.
  207. \****************************************************************************/
  208.  
  209. VOID PASCAL DlgOpenName(hwnd, pdlf)
  210. HWND hwnd;
  211. PDLF pdlf;
  212.     {
  213.     PSZ  lpch;
  214.     USHORT wVal;
  215.     CHAR sz[MAX_FNAME_LEN];
  216.  
  217.     /* try using current name as a directory */
  218.     lstrcpy((PSZ)sz, (PSZ)pdlf->szFileName);
  219.     if (!DlgSearchSpec((PSZ)sz))
  220.         DlgAddSearchExt(pdlf, (PSZ)sz);
  221.     if (DlgDirList(hwnd, (PSZ)sz, ID_DIRLIST, ID_FILELIST, ID_PATH,
  222.                    pdlf->rgbFlags))
  223.         {
  224.         /* name was a directory, extract and set file name */
  225.         lpch = FileInPath((PSZ)sz);
  226.         lstrcpy((PSZ)pdlf->szFileName, lpch);
  227.         WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
  228.                          (PSZ)pdlf->szFileName);
  229.         }
  230.     else
  231.         /* try to open name as a file */
  232.         if ((wVal = DlgOpenFile(pdlf, hwnd)) != TDF_NOOPEN)
  233.             WinDismissDlg(hwnd, wVal);
  234.     }
  235.  
  236.  
  237.  
  238.  
  239. /****************************************************************************\
  240. * This function is the SaveAs dialog box window procedure.  It handles input,
  241. * tests for legal filenames and uses message boxes to report any problems.
  242. *
  243. * Return values are:
  244. *     TDF_INVALID - Library error (internal error),
  245. *     TDF_NOOPEN  - User hits cancel
  246. *   Specific for DLG_NOOPEN
  247. *     TDF_NEWSAVE - user wants to save to a new file (file not created)
  248. *     TDF_OLDSAVE - user wants to save over existing file (file not opened)
  249. *   else
  250. *     TDF_NEWSAVE - user wants to save to a new file (file left open)
  251. *     TDF_OLDSAVE - user wants to save over existing file (file left open)
  252. \****************************************************************************/
  253.  
  254. MRESULT EXPENTRY DlgSaveAsWndProc(hwnd, msg, mp1, mp2)
  255. HWND   hwnd;
  256. USHORT msg;
  257. MPARAM mp1;
  258. MPARAM mp2;
  259.     {
  260.     PDLF    pdlf;
  261.     PSZ     lpchFile;
  262.     CHAR    sz[MAX_FNAME_LEN];
  263.  
  264.     switch (msg)
  265.         {
  266.     case WM_INITDLG:
  267.         /* Store pdlf, set instructions, limit text size */
  268.         DlgInitSaveAs(hwnd, LONGFROMMP(mp2));
  269.  
  270.         /* fill static field with path name and fill list box with
  271.            filenames that lMatch spec */
  272.         if (!DlgDirList(hwnd, ((PDLF)(mp2))->pszExt+1, ID_DIRLIST,
  273.                         ID_FILELIST, ID_PATH, ((PDLF)(mp2))->rgbFlags))
  274.             /* NOTE: shouldn't we post a message if something screws up? */
  275.             WinDismissDlg(hwnd, TDF_INVALID);
  276.         break;
  277.  
  278.     case WM_COMMAND:
  279.         pdlf = (PDLF) WinQueryWindowULong(hwnd, 0);
  280.         switch (SHORT1FROMMP(mp1))
  281.            {
  282.         case MBID_OK:
  283.             /* get text from edit box */
  284.             WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
  285.                                CBROOTNAMEMAX, (PSZ)pdlf->szFileName);
  286.         Upper((PSZ)pdlf->szFileName);
  287.         if( DlgSearchSpec( (PSZ)pdlf->szFileName))
  288.         {
  289.         DlgDirList( hwnd
  290.               , (PSZ)pdlf->szFileName
  291.               , ID_DIRLIST
  292.               , ID_FILELIST
  293.               , ID_PATH
  294.               , pdlf->rgbFlags );
  295.         lstrcpy( (PSZ)pdlf->szLastWild
  296.                , FileInPath( (PSZ)pdlf->szFileName));
  297.         lstrcpy( (PSZ)pdlf->szFileName, (PSZ)pdlf->szLastFile);
  298.         WinSetWindowText( WinWindowFromID( hwnd, ID_EDIT)
  299.                 , (PSZ)pdlf->szFileName );
  300.         }
  301.         else if( lstrlen( (PSZ)pdlf->szFileName))
  302.         DlgSaveAsName( hwnd, pdlf);
  303.             break;
  304.  
  305.         case MBID_CANCEL:
  306.             WinDismissDlg(hwnd, TDF_NOSAVE);
  307.             break;
  308.  
  309.     case MBID_HELP:
  310.         /* Help button pressed */
  311.         WinMessageBox( HWND_DESKTOP
  312.              , hwnd
  313.              , pdlf->pszInstructions
  314.              , pdlf->pszTitle
  315.              , NULL
  316.              , MB_OK | MB_APPLMODAL );
  317.         break;
  318.             }
  319.         break;
  320.  
  321.     case WM_CONTROL:
  322.         pdlf = (PDLF) WinQueryWindowULong(hwnd, 0);
  323.         switch (SHORT1FROMMP(mp1))
  324.             {
  325.         case ID_DIRLIST:
  326.             /* user clicked in directory list box */
  327.             switch (SHORT2FROMMP(mp1))
  328.                 {
  329.             case LN_SELECT:
  330.                 /* single click case */
  331.                 /* get current edit string */
  332.                 WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
  333.                                    CBROOTNAMEMAX, (PSZ)sz);
  334.                 Upper((PSZ)sz);
  335.  
  336.                 /* get selected string */
  337.                 if (DlgDirSelect(hwnd, (PSZ)pdlf->szFileName, ID_DIRLIST))
  338.                     {
  339.                     /* if edit field contains wild card, then append file
  340.                part to selected directory, otherwise append
  341.                last wildcard search spec */
  342.                     lpchFile = FileInPath((PSZ)sz);
  343.             if( DlgSearchSpec( lpchFile))
  344.             {
  345.             lstrcat( (PSZ)pdlf->szFileName, lpchFile );
  346.             lstrcpy( (PSZ)pdlf->szLastWild, lpchFile);
  347.             }
  348.             else
  349.             {
  350.             lstrcat( (PSZ)pdlf->szFileName, (PSZ)pdlf->szLastWild );
  351.             lstrcpy( (PSZ)pdlf->szLastFile, lpchFile);
  352.             }
  353.                     /* set edit box to resulting name */
  354.                     WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
  355.                                      (PSZ)pdlf->szFileName);
  356.                     }
  357.                 break;
  358.  
  359.             case LN_ENTER:
  360.         /* get text from edit box */
  361.         WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
  362.                    CBROOTNAMEMAX, (PSZ)pdlf->szFileName);
  363.         Upper((PSZ)pdlf->szFileName);
  364.         if( DlgSearchSpec( (PSZ)pdlf->szFileName))
  365.             {
  366.             DlgDirList( hwnd
  367.                   , (PSZ)pdlf->szFileName
  368.                   , ID_DIRLIST
  369.                   , ID_FILELIST
  370.                   , ID_PATH
  371.                   , pdlf->rgbFlags );
  372.             lstrcpy( (PSZ)pdlf->szLastWild
  373.                , FileInPath( (PSZ)pdlf->szFileName));
  374.             lstrcpy( (PSZ)pdlf->szFileName, (PSZ)pdlf->szLastFile);
  375.             WinSetWindowText( WinWindowFromID( hwnd, ID_EDIT)
  376.                     , (PSZ)pdlf->szFileName );
  377.             }
  378.         break;
  379.         }
  380.             break;
  381.  
  382.         case ID_FILELIST:
  383.             /* user clicked in file list box */
  384.             switch (SHORT2FROMMP(mp1))
  385.                 {
  386.             case LN_SELECT:
  387.                 /* single click case */
  388.  
  389.         /* get current edit string */
  390.         /* if it contains a wildcard, save it before obliteration */
  391.                 WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
  392.                                    CBROOTNAMEMAX, (PSZ)sz);
  393.         Upper((PSZ)sz);
  394.         if( DlgSearchSpec( (PSZ)sz))
  395.             lstrcpy( (PSZ)pdlf->szLastWild, FileInPath( (PSZ)sz));
  396.  
  397.                 /* get selected file name */
  398.                 DlgDirSelect(hwnd, (PSZ)pdlf->szFileName, ID_FILELIST);
  399.                 /* set edit box to resulting name */
  400.                 WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
  401.                                  (PSZ)pdlf->szFileName);
  402.                 break;
  403.  
  404.             case LN_ENTER:
  405.                 /* double click case, single click already processed */
  406.         DlgSaveAsName(hwnd, pdlf);
  407.                 break;
  408.                 }
  409.             break;
  410.             }
  411.         break;
  412.  
  413.     default:
  414.         return (WinDefDlgProc(hwnd, msg, mp1, mp2));
  415.         }
  416.  
  417.     return (MRFROMLONG(0L));    /* message processed */
  418.     }
  419.  
  420.  
  421.  
  422. /******************************************************************************/
  423. /*                                          */
  424. /* This function attempts to open a file for writing.  It queries if over-    */
  425. /* write is OK if the file already exists.                      */
  426. /*                                          */
  427. /******************************************************************************/
  428. VOID PASCAL DlgSaveAsName( hwnd, pdlf)
  429. HWND  hwnd;
  430. PDLF  pdlf;
  431.     {
  432.     USHORT  usTdf;
  433.  
  434.     /* add extension if there is not one already */
  435.     AddExt((PSZ)pdlf->szFileName, pdlf->pszExt);
  436.     /* test file name legality */
  437.     if (!DlgParseFile((PSZ)pdlf->szFileName,
  438.               (PSZ)pdlf->szOpenFile, FALSE, FALSE))
  439.     {
  440.     /* illegal filename */
  441.     DlgAlertBox(hwnd, IDS_IFN, pdlf,
  442.             MB_OK | MB_ICONEXCLAMATION);
  443.     return;
  444.     }
  445.     usTdf = TDF_NEWSAVE;
  446.     /* test if file already exists */
  447.     if (DlgParseFile((PSZ)pdlf->szFileName,
  448.              (PSZ)pdlf->szOpenFile, TRUE, FALSE))
  449.     {
  450.     /* overwrite? */
  451.     if (DlgAlertBox(hwnd, IDS_REF, pdlf,
  452.             MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION)
  453.         == MBID_NO)
  454.         return;
  455.     usTdf = TDF_OLDSAVE;
  456.     }
  457.     if (!(pdlf->rgbAction & DLG_NOOPEN) &&
  458.     !(OpenFile( (PSZ)pdlf->szFileName
  459.           , pdlf->phFile
  460.           , (PSZ)pdlf->szOpenFile
  461.           , OF_WRITE)))
  462.     {
  463.     DlgAlertBox(hwnd, IDS_EOF, pdlf,
  464.             MB_OK | MB_ICONEXCLAMATION);
  465.     return;
  466.     }
  467.     WinDismissDlg(hwnd, usTdf);
  468.     }
  469.  
  470.  
  471.  
  472. /****************************************************************************\
  473. * This function initializes the SaveAs dialog box.  It puts the current
  474. * directory string in the ID_PATH field and initializes the edit box
  475. * with the proposed filename.  It is the simple relative file name if current
  476. * dir == pdlf->szOpenFile.  Otherwise, it is the fully qualified name.
  477. \****************************************************************************/
  478.  
  479. VOID PASCAL DlgInitSaveAs (hwnd, lpParm)
  480. HWND hwnd;
  481. ULONG lpParm;
  482.     {
  483.     PDLF pdlf;
  484.     CHAR sz[MAX_FNAME_LEN];
  485.     PSZ  lpszFile, lpszFN, lpszCD;
  486.  
  487.     /* set pdlf local to window */
  488.     pdlf = (PDLF) lpParm;
  489.     WinSetWindowULong(hwnd, 0, lpParm);
  490.  
  491.     /* set edit box text size limit */
  492.     WinSendDlgItemMsg(hwnd, ID_EDIT, EM_SETTEXTLIMIT, (MPARAM)CBROOTNAMEMAX, 0L);
  493.  
  494.     /* set title window */
  495.     if (pdlf->pszTitle != (PSZ)NULL)
  496.     WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), pdlf->pszTitle);
  497.  
  498.     /* set szLastWild to search spec */
  499.     if (pdlf->pszExt != (PSZ)NULL)
  500.     lstrcpy( (PSZ)pdlf->szLastWild, (PSZ)pdlf->pszExt+1 );
  501.  
  502.     /* get current directory */
  503.     DosSearchPath(0, (PSZ)szDot, (PSZ)szStarStar, (PSZ)sz, MAX_FNAME_LEN);
  504.     lpszFile = FileInPath((PSZ)sz);
  505.     if (lpszFile > (PSZ)sz + 3)
  506.         lpszFile--;
  507.     *lpszFile = '\0';
  508.  
  509.     /* compare path part name to previously opened file name and
  510.        make the file name relative if they are the same */
  511.     lpszFN = (PSZ)pdlf->szOpenFile;
  512.     lpszCD = (PSZ)sz;
  513.     lpszFile = FileInPath((PSZ)pdlf->szOpenFile);
  514.     while (lpszFN < lpszFile && *lpszFN == *lpszCD)
  515.         {
  516.         lpszFN = NextChar(lpszFN);
  517.         lpszCD = NextChar(lpszCD);
  518.         }
  519.     if (*lpszCD)
  520.         lpszFN = (PSZ)pdlf->szOpenFile;
  521.     else if (*lpszFN == '\\')
  522.     lpszFN = NextChar(lpszFN);
  523.     Upper( lpszFN);
  524.     WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT), lpszFN);
  525.     lstrcpy( (PSZ)pdlf->szLastFile, lpszFN);
  526.  
  527.     /* set current path field */
  528.     WinSetWindowText(WinWindowFromID(hwnd, ID_PATH),
  529.                      DlgFitPathToBox(hwnd, ID_PATH, (PSZ)sz));
  530.     }
  531.  
  532.  
  533.  
  534.  
  535. /****************************************************************************\
  536. * This function returns the filename part of the given path string.
  537. \****************************************************************************/
  538.  
  539. PSZ  EXPENTRY FileInPath(lpsz)
  540. PSZ  lpsz;
  541.     {
  542.     PSZ  lpch;
  543.  
  544.     /* strip path/drive specification from name if there is one */
  545.     lpch = lpsz + lstrlen(lpsz);
  546.     while (lpch > lpsz)
  547.         {
  548.         lpch = PrevChar(lpsz, lpch);
  549.         if (*lpch == '\\' || *lpch == ':')
  550.             {
  551.             lpch = NextChar(lpch);
  552.             break;
  553.             }
  554.         }
  555.     return(lpch);
  556.     }
  557.  
  558.  
  559.  
  560.  
  561. /****************************************************************************\
  562. * This function adds the extension to a file name if it is missing.
  563. \****************************************************************************/
  564.  
  565. VOID EXPENTRY AddExt(lpsz, lpszExt)
  566. PSZ  lpsz;
  567. PSZ  lpszExt;
  568.     {
  569.     PSZ  lpch;
  570.  
  571.     lpch = lpsz + lstrlen(lpsz);
  572.     while (*lpch != '.' && *lpch != '\\' && *lpch != ':' && lpch > lpsz)
  573.         lpch = PrevChar(lpsz, lpch);
  574.  
  575.     if (*lpch != '.')
  576.         lstrcat(lpsz, (PSZ)(lpszExt+2));
  577.     }
  578.  
  579.  
  580.  
  581.  
  582. /****************************************************************************\
  583. * This function adds the "appropriate" extension to a filename, partial
  584. * filename, search spec or partial search spec.
  585. \****************************************************************************/
  586.  
  587. VOID PASCAL DlgAddSearchExt(pdlf, lpszEdit)
  588. PDLF pdlf;
  589. PSZ  lpszEdit;
  590.     {
  591.     PSZ  lpchLast;
  592.  
  593.     lpchLast = PrevChar(lpszEdit, lpszEdit + lstrlen(lpszEdit));
  594.     if (*lpchLast == '\\' || *lpchLast == ':')
  595.         lstrcat(lpszEdit, pdlf->pszExt + 1);
  596.     else
  597.         lstrcat(lpszEdit, pdlf->pszExt);
  598.     }
  599.  
  600.  
  601.  
  602.  
  603. /****************************************************************************\
  604. * This function returns TRUE if lpsz contains a wildcard character '*' or '?';
  605. \****************************************************************************/
  606.  
  607. BOOL PASCAL DlgSearchSpec(lpsz)
  608. PSZ  lpsz;
  609.    {
  610.     for (; *lpsz; lpsz = NextChar(lpsz))
  611.         if (*lpsz == '*' || *lpsz == '?')
  612.             return TRUE;
  613.     return FALSE;
  614.    }
  615.  
  616.  
  617.  
  618.  
  619. /****************************************************************************\
  620. * This function displays an error or warning msg.
  621. \****************************************************************************/
  622.  
  623. int PASCAL DlgAlertBox(hwnd, ids, pdlf, wStyle)
  624. HWND hwnd;
  625. int ids;
  626. PDLF pdlf;
  627. USHORT wStyle;
  628.     {
  629.     /* note:  5th param is idHelp */
  630.     return (AlertBox(hwnd, ids, (PSZ)pdlf->szFileName, pdlf->pszAppName,
  631.                          NULL, wStyle | MB_APPLMODAL));
  632.     }
  633.