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