home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / pm / controls / sty_file.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  24KB  |  721 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : STY_FILE.C
  4. *
  5. *  Description : This module contains the code for the
  6. *                WM_COMMAND messages posted by the standard
  7. *                File menu.
  8. *
  9. *  Concepts    : Open, close, read, write of files.
  10. *                File selection through the use of the
  11. *                standard file dialog.
  12. *
  13. *  API's       : WinSendMsg
  14. *                WinLoadString
  15. *                WinFileDlg
  16. *                DosOpen
  17. *                DosQueryFileInfo
  18. *                DosClose
  19. *                DosRead
  20. *                DosAllocMem
  21. *                DosFreeMem
  22. *                WinPostMsg
  23. *                DosWrite
  24. *                WinQueryTaskTitle
  25. *                WinLoadString
  26. *                WinSetWindowText
  27. *                WinQueryWindowULong
  28. *
  29. *  Copyright (C) 1992, 1996 IBM Corporation
  30. *
  31. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  32. *      sample code created by IBM Corporation. This sample code is not
  33. *      part of any standard or IBM product and is provided to you solely
  34. *      for  the purpose of assisting you in the development of your
  35. *      applications.  The code is provided "AS IS", without
  36. *      warranty of any kind.  IBM shall not be liable for any damages
  37. *      arising out of your use of the sample code, even if they have been
  38. *      advised of the possibility of such damages.                                                    *
  39. *
  40. ************************************************************************/
  41.  
  42. /*  Include files, macros, defined constants, and externs               */
  43. #define INCL_WINFRAMEMGR
  44. #define INCL_WINWINDOWMGR
  45. #define INCL_WINSWITCHLIST
  46. #define INCL_WINMLE
  47. #define INCL_WINSTDFILE
  48.  
  49. #include <os2.h>
  50. #include <string.h>
  51. #include "sty_main.h"
  52. #include "sty_xtrn.h"
  53. #include "sty_help.h"
  54. #include "sty_dlg.h"
  55.  
  56. /*  Global variables                                                    */
  57. CHAR szFullPath[CCHMAXPATH] = "";
  58.  
  59. /*********************************************************************
  60.  *  Name: FileNew
  61.  *
  62.  *  Description : Processes the File menu's New item
  63.  *
  64.  *  Concepts : Called whenever New from the File menu is selected.
  65.  *
  66.  *  API's : WinSendMsg
  67.  *
  68.  *  Parameters : mp2 - Message parameter 2
  69.  *
  70.  *  Returns : VOID
  71.  *
  72.  ****************************************************************/
  73. VOID FileNew( MPARAM mp2)
  74. {
  75.    /* Save file if changed                                              */
  76.    if ((BOOL)WinSendMsg(hwndMLE, MLM_QUERYCHANGED, MPVOID, MPVOID))
  77.    {
  78.       SHORT sMsgBoxResponse = MessageBox(hwndMLE, IDMSG_FILECHANGED,
  79.                                          MB_QUERY | MB_YESNOCANCEL, FALSE);
  80.  
  81.       if (sMsgBoxResponse == MBID_CANCEL)   /* if user cancels the New,  */
  82.          return;                           /* then return               */
  83.       else
  84.          if (sMsgBoxResponse == MBID_YES)
  85.             FileSave(MPVOID);
  86.       /*
  87.        * If sMsgBoxResponse == MBID_NO, continue with New File processing
  88.        */
  89.    }
  90.  
  91.    /*
  92.     * disable redrawing of the MLE so the text doesn't "flash" when
  93.     * the MLE is cleared
  94.     */
  95.    WinSendMsg(hwndMLE, MLM_DISABLEREFRESH, MPVOID, MPVOID); 
  96.  
  97.    /*
  98.     * Clear the MLE by selecting all of the text and clearing it
  99.     */
  100.    WinSendMsg(hwndMLE, MLM_SETSEL, MPFROMSHORT(0),
  101.              (MPARAM)WinSendMsg(hwndMLE, MLM_QUERYTEXTLENGTH, MPVOID, MPVOID));
  102.  
  103.    WinSendMsg(hwndMLE, MLM_CLEAR, MPVOID, MPVOID);
  104.  
  105.    /*
  106.     * Reset the changed flag
  107.     */
  108.    WinSendMsg(hwndMLE, MLM_SETCHANGED, MPFROMSHORT((BOOL)FALSE), MPVOID);
  109.  
  110.    /*
  111.     * Enable redrawing of the MLE
  112.     */
  113.    WinSendMsg(hwndMLE, MLM_ENABLEREFRESH, MPVOID, MPVOID);
  114.  
  115.    /*
  116.     * Reset file name to NULL and update the main title bar
  117.     */
  118.    szFullPath[0] = 0;
  119.    UpdateTitleText(hwndMainFrame);
  120.  
  121.    /*
  122.     *  This routine currently doesn't use the mp2 parameter but
  123.     *  it is referenced here to prevent an 'Unreferenced Parameter'
  124.     *  warning at compile time.
  125.     */
  126.    mp2;
  127. }   /* End of FileNew()                                                  */
  128.  
  129. /*********************************************************************
  130.  *  Name: FileOpen
  131.  *
  132.  *  Description : Processes the File menu's Open item.
  133.  *
  134.  *  Concepts : Called whenever New from the File menu is
  135.  *             selected.  Calls the standard file open
  136.  *             dialog to get the file name.  The file name
  137.  *             is passed onto DosOpen which returns the
  138.  *             handle to the file.  The file input
  139.  *             procedure is called and then the file
  140.  *             handle is closed.
  141.  *
  142.  *  API's : WinLoadString
  143.  *          WinFileDlg
  144.  *          DosOpen
  145.  *          DosQueryFileInfo
  146.  *          DosClose
  147.  *          DosRead
  148.  *          DosAllocMem
  149.  *          DosFreeMem
  150.  *
  151.  *  Parameters : mp2 - Message parameter 2
  152.  *
  153.  *  Returns : VOID
  154.  *
  155.  ****************************************************************/
  156. VOID FileOpen( MPARAM mp2)
  157. {
  158.    FILEDLG fileDialog;
  159.    CHAR szTitle[MESSAGELEN], szButton[MESSAGELEN];
  160.  
  161.    /* Save file if changed                                              */
  162.    if ((BOOL)WinSendMsg(hwndMLE, MLM_QUERYCHANGED, MPVOID, MPVOID))
  163.    {
  164.       SHORT sMsgBoxResponse = MessageBox(hwndMLE, IDMSG_FILECHANGED,
  165.            MB_QUERY | MB_YESNOCANCEL, FALSE);
  166.  
  167.       if (sMsgBoxResponse == MBID_CANCEL)   /* if user cancels the New,  */
  168.          return;                           /* then return               */
  169.       else
  170.          if (sMsgBoxResponse == MBID_YES)
  171.             FileSave(MPVOID);
  172.       /*
  173.        * If sMsgBoxResponse == MBID_NO, continue with Open File processing
  174.        */
  175.    }
  176.  
  177.    fileDialog.cbSize = sizeof(FILEDLG);
  178.  
  179.    if (!WinLoadString(hab, NULLHANDLE, IDS_OPENDLGTITLE, MESSAGELEN, szTitle))
  180.    {
  181.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
  182.       return;
  183.    }
  184.  
  185.    if (!WinLoadString(hab, NULLHANDLE, IDS_OPENDLGBUTTON, MESSAGELEN, szButton))
  186.    {
  187.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
  188.       return;
  189.    }
  190.  
  191.    fileDialog.pszTitle = szTitle;
  192.    fileDialog.pszOKButton = szButton;
  193.    fileDialog.ulUser = 0UL;
  194.    fileDialog.fl = FDS_HELPBUTTON | FDS_CENTER | FDS_OPEN_DIALOG;
  195.    fileDialog.pfnDlgProc = (PFNWP)OpenSaveFilterDlgProc;
  196.    fileDialog.lReturn = 0L;
  197.    fileDialog.lSRC = 0L;
  198.    fileDialog.hMod = NULLHANDLE;
  199.    fileDialog.usDlgId = IDD_FILEOPEN;
  200.    fileDialog.x = 0;
  201.    fileDialog.y = 0;
  202.  
  203.    if (!WinLoadString(hab, NULLHANDLE, IDS_FILEOPENEXT, CCHMAXPATH,
  204.                      fileDialog.szFullFile))
  205.    {
  206.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
  207.       return;
  208.    }
  209.  
  210.    fileDialog.pszIType = NULL;
  211.    fileDialog.papszITypeList = NULL;
  212.    fileDialog.pszIDrive = NULL;
  213.    fileDialog.papszIDriveList = NULL;
  214.    fileDialog.sEAType = 0;
  215.    fileDialog.papszFQFilename = NULL;
  216.    fileDialog.ulFQFCount = 0UL;
  217.  
  218.    /*
  219.     *Call the standard file dialog to get the file
  220.     */
  221.    if (!WinFileDlg(HWND_DESKTOP, hwndMain, (PFILEDLG)&fileDialog))
  222.       return;
  223.  
  224.    /*
  225.     *  Upon sucessful return of a file, open it for reading
  226.     */
  227.  
  228.    if (fileDialog.lReturn == ID_OK)
  229.    {
  230.       HFILE hfile;
  231.       ULONG ulAction;
  232.       FILESTATUS fileStatus;
  233.       PVOID pvBuf;
  234.       IPT iptOffset = 0;
  235.  
  236.       if ( DosOpen(fileDialog.szFullFile, &hfile, &ulAction, 0, FILE_NORMAL,
  237.              FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, NULL))
  238.       {
  239.          MessageBox(hwndMain, IDMSG_CANNOTOPENINPUTFILE, MB_OK | MB_ERROR,
  240.             FALSE);
  241.          return;
  242.       }
  243.       /*
  244.        * Copy file name into file name buffer
  245.        */
  246.       strcpy(szFullPath, fileDialog.szFullFile);
  247.  
  248.       /*
  249.        * Get the length of the file
  250.        */
  251.  
  252.       if (DosQueryFileInfo(hfile, 1, (PVOID)&fileStatus, sizeof(FILESTATUS)))
  253.       {
  254.          MessageBox(hwndMain, IDMSG_CANNOTGETFILEINFO, MB_OK | MB_ERROR,
  255.               FALSE);
  256.          DosClose(hfile);
  257.          return;
  258.       }
  259.       /*
  260.        * Allocate a buffer for the file
  261.        */
  262.       if (DosAllocMem((PPVOID)&pvBuf, (ULONG)fileStatus.cbFileAlloc, fALLOC))
  263.       {
  264.          MessageBox(hwndMain, IDMSG_CANNOTALLOCATEMEMORY, MB_OK | MB_ERROR,
  265.                     FALSE);
  266.  
  267.          DosClose(hfile);
  268.          return;
  269.       }
  270.       /*
  271.        * Read in the file
  272.        */
  273.       if (DosRead(hfile, pvBuf, fileStatus.cbFileAlloc, &ulAction))
  274.       {
  275.          MessageBox(hwndMain, IDMSG_CANNOTREADFILE, MB_OK | MB_ERROR, FALSE);
  276.          DosClose(hfile);
  277.          return;
  278.       }
  279.       /*
  280.        * Set the file into the MLE
  281.        */
  282.       WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT, MPFROMP((PBYTE)pvBuf),
  283.                                 MPFROMSHORT(fileStatus.cbFileAlloc));
  284.  
  285.       /*
  286.        * Import to MLE starting at offset 0
  287.        */
  288.  
  289.       WinSendMsg(hwndMLE, MLM_IMPORT, MPFROMP(&iptOffset),
  290.                               MPFROMSHORT(fileStatus.cbFileAlloc));
  291.  
  292.       /*
  293.        * Reset the changed flag
  294.        */
  295.       WinSendMsg(hwndMLE, MLM_SETCHANGED, MPFROMSHORT((BOOL)FALSE), NULL);
  296.  
  297.       DosFreeMem(pvBuf);
  298.  
  299.       DosClose(hfile);
  300.  
  301.       UpdateTitleText(hwndMainFrame);
  302.    }
  303.    /*
  304.     *  This routine currently doesn't use the mp2 parameter but
  305.     *  it is referenced here to prevent an 'Unreferenced Parameter'
  306.     *  warning at compile time.
  307.     */
  308.    mp2;
  309. }   /* End of FileOpen()                                                */
  310.  
  311.  
  312. /*********************************************************************
  313.  *  Name: FileSave
  314.  *
  315.  *  Description : Processes the File menu's Save item.
  316.  *
  317.  *  Concepts : Gets file name for untitled files, opens file
  318.  *             writes file to disk, closes file.
  319.  *
  320.  *  API's : DosOpen
  321.  *          DosClose
  322.  *
  323.  *  Parameters : mp2 - Message parameter 2
  324.  *
  325.  *  Returns : VOID
  326.  *
  327.  ****************************************************************/
  328. VOID FileSave( MPARAM mp2)
  329. {
  330.    HFILE hfile;
  331.    ULONG ulAction;
  332.    /*
  333.     * If the file currently is untitled, we will need to get a file
  334.     * name from the user before we can open the file.  Getting a
  335.     * file name is normally done during the FileSaveAs operation
  336.     * so we will treat this save as a SaveAs and call FileSaveAs().
  337.     * If the file is titled, then we save the file.
  338.     *
  339.     * NOTE:  This routine will be called by FileSaveAs(), but only
  340.     *  after a valid file name has been obtained.  So, FileSaveAs()
  341.     *  will not be called again from this routine.
  342.     */
  343.    if (szFullPath[0] == 0)
  344.    {
  345.       FileSaveAs(mp2);
  346.       return;
  347.    }
  348.  
  349.    /*
  350.     * Open the file
  351.     */
  352.    if ( DosOpen(szFullPath, &hfile, &ulAction, 0, FILE_NORMAL, FILE_OPEN |
  353.        FILE_CREATE, OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE, NULL))
  354.    {
  355.       MessageBox(hwndMain, IDMSG_CANNOTOPENOUTPUTFILE, MB_OK|MB_ERROR, FALSE);
  356.       return;
  357.    }
  358.  
  359.    WriteFileToDisk(hfile);
  360.  
  361.    DosClose(hfile);
  362.    return;
  363. }   /*  End of FileSave()                                               */
  364.  
  365. /*********************************************************************
  366.  *  Name: FileSaveAs
  367.  *
  368.  *  Description : Processes the File menu's Save As item.
  369.  *
  370.  *  Concepts : Called whenever Save As from the File menu is
  371.  *             selected.
  372.  *
  373.  *  API's : DosOpen
  374.  *          DosClose
  375.  *
  376.  *  Parameters : mp2 - Message parameter 2
  377.  *
  378.  *  Returns : VOID
  379.  *
  380.  ********************************************************************/
  381. VOID FileSaveAs( MPARAM mp2)
  382. {
  383.    /*
  384.     * Infinite loop until we break out of it
  385.     */
  386.    while(TRUE)
  387.    {
  388.       HFILE hfile;
  389.       ULONG ulAction;
  390.    /*
  391.     * If no file name, then get a file name
  392.     */
  393.       if (!GetFileName())
  394.          return;
  395.    /*
  396.     * See if the file exists.  If it does, then confirm that the
  397.     * user wants to overwrite it.  If he doesn't, then get a new
  398.     * file name
  399.     */
  400.       if ( DosOpen(szFullPath,         /* file name from, GetFileName()    */
  401.                    &hfile,             /* handle of opened file            */
  402.                    &ulAction,
  403.                    0,
  404.                    FILE_NORMAL,
  405.                    FILE_OPEN | FILE_CREATE,
  406.                    OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE,
  407.                    NULL))
  408.      {
  409.         MessageBox(hwndMain, IDMSG_CANNOTOPENOUTPUTFILE, MB_OK|MB_ERROR, FALSE);
  410.         return;
  411.      }
  412.      else
  413.         DosClose(hfile);
  414.  
  415.      /*
  416.       * If file exists, ask if we want to overwrite it
  417.       */
  418.      if (ulAction == FILE_EXISTED)
  419.      {
  420.         SHORT sMsgBoxResponse = MessageBox(hwndMLE, IDMSG_OVERWRITEFILE, 
  421.                                            MB_QUERY | MB_YESNOCANCEL, FALSE);
  422.  
  423.        if (sMsgBoxResponse == MBID_CANCEL)
  424.           return;
  425.  
  426.         if (sMsgBoxResponse == MBID_YES)
  427.            break;
  428.        /*
  429.         * If user selected no, repeat the sequence
  430.         */
  431.       }
  432.       else
  433.          break;                      /* file didn't exist               */
  434.    }                                 /* while(TRUE)                     */
  435.    UpdateTitleText(hwndMainFrame);
  436.    /*
  437.     * Now that we have a valid file name, save the file.  This is
  438.     * normally done under the File Save function so we can just
  439.     * call the FileSave() function here.  Note that FileSave() will
  440.     * not call FileSaveAs() back since there is a valid file name
  441.     */
  442.     FileSave(mp2);
  443.     return;
  444. }       /* End of FileSaveAs()                                          */
  445.  
  446. /****************************************************************
  447.  *  Name: WriteFileToDisk
  448.  *
  449.  *  Description : Writes the current file to the file in szFileName
  450.  *
  451.  *  Concepts : Called from FileSave and FileSaveAs when a file is
  452.  *             to be saved to disk.  Routine uses the file handle
  453.  *             specified and gets the text from the MLE and
  454.  *             writes the text to the file.
  455.  *
  456.  *  API's : WinSendmsg
  457.  *          DosAllocMem
  458.  *          DosWrite
  459.  *          DosFreeMem
  460.  *
  461.  *  Parameters : hfile - handle of file to save
  462.  *
  463.  *  Returns: Void
  464.  *
  465.  ****************************************************************/
  466. VOID WriteFileToDisk( HFILE hfile)
  467. {
  468.    ULONG ulWrite;
  469.    PVOID pvBuf;
  470.    ULONG ulOffset;             /* offset in buffer                    */
  471.    ULONG cbExport;             /* # of bytes to export from the MLE   */
  472.    /*
  473.     * Get the length of the file
  474.     */
  475.    ULONG ulFileLen = (ULONG)WinSendMsg(hwndMLE, MLM_QUERYTEXTLENGTH, MPVOID, MPVOID);
  476.  
  477.    if (!ulFileLen)
  478.       return;
  479.  
  480.    /*
  481.     * Allocate a buffer for the file
  482.     */
  483.    if (DosAllocMem((PPVOID) &pvBuf, ulFileLen, fALLOC))
  484.    {
  485.       MessageBox(hwndMLE, IDMSG_CANNOTALLOCATEMEMORY, MB_OK | MB_ERROR,
  486.            FALSE);
  487.       return;
  488.    }
  489.  
  490.    /*
  491.     * Get the file from the MLE
  492.     */
  493.    cbExport = ulFileLen;
  494.    WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT, MPFROMP((PBYTE)pvBuf),
  495.         MPFROMLONG(cbExport));
  496.  
  497.    /*
  498.    * Export MLE starting at offset 0
  499.    */
  500.    ulOffset = 0UL;
  501.    WinSendMsg(hwndMLE, MLM_EXPORT, MPFROMP(&ulOffset), MPFROMLONG(&cbExport));
  502.  
  503.    /*
  504.     * Write the file
  505.     */
  506.    if (DosWrite(hfile, pvBuf, ulFileLen, &ulWrite))
  507.    {
  508.       MessageBox(hwndMLE, IDMSG_CANNOTWRITETOFILE, MB_OK | MB_ERROR, FALSE);
  509.       return;
  510.    }
  511.  
  512.    /*
  513.     * Reset the changed flag
  514.     */
  515.    WinSendMsg(hwndMLE, MLM_SETCHANGED, MPFROMSHORT((BOOL)FALSE), MPVOID);
  516.  
  517.    DosFreeMem(pvBuf);
  518. }          /*   End of WriteFileToDisk()                                */
  519.  
  520. /*********************************************************************
  521.  *  Name : GetFileName
  522.  *
  523.  *  Description : Gets the name of the save file.
  524.  *
  525.  *  Concepts : Called when the user is needs to supply a name
  526.  *             for the file to be saved.  Calls the standard
  527.  *             file open dialog to get the file name.
  528.  *
  529.  *  API's : WinLoadString
  530.  *          WinFileDlg
  531.  *
  532.  *  Parameters : None
  533.  *
  534.  *  Returns: Void
  535.  *
  536.  ****************************************************************/
  537. BOOL GetFileName(VOID)
  538. {
  539.    FILEDLG fileDialog;
  540.    CHAR szTitle[MESSAGELEN], szButton[MESSAGELEN];
  541.  
  542.    if (!WinLoadString(hab, NULLHANDLE, IDS_SAVEDLGTITLE, MESSAGELEN, szTitle))
  543.    {
  544.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
  545.       return FALSE;
  546.    }
  547.  
  548.    if (!WinLoadString(hab, NULLHANDLE, IDS_SAVEDLGBUTTON, MESSAGELEN, szButton))
  549.    {
  550.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
  551.       return FALSE;
  552.    }
  553.  
  554.    fileDialog.cbSize = sizeof(FILEDLG);       /* Size of FILEDLG structure. */
  555.    fileDialog.fl = FDS_HELPBUTTON |   /* FDS_ flags. Alter behavior of dlg. */
  556.                     FDS_CENTER | FDS_SAVEAS_DIALOG | FDS_ENABLEFILELB;
  557.    fileDialog.ulUser = 0UL;                          /* User defined field. */
  558.    fileDialog.lReturn = 0L;           /* Result code from dialog dismissal. */
  559.    fileDialog.lSRC = 0L;                             /* System return code. */
  560.    fileDialog.pszTitle = szTitle;        /* String to display in title bar. */
  561.    fileDialog.pszOKButton = szButton;    /* String to display in OK button. */
  562.                                       /* Entry point to custom dialog proc. */
  563.    fileDialog.pfnDlgProc = (PFNWP)OpenSaveFilterDlgProc;
  564.    fileDialog.pszIType = NULL;         /* Pointer to string containing      */
  565.                                        /*   initial EA type filter. Type    */
  566.                                        /*   does not have to exist in list. */
  567.    fileDialog.papszITypeList = NULL;   /* Pointer to table of pointers that */
  568.                                        /*   point to null terminated Type   */
  569.                                        /*   strings. End of table is marked */
  570.                                        /*   by a NULL pointer.              */
  571.    fileDialog.pszIDrive = NULL;          /* Pointer to string containing    */
  572.                                          /*   initial drive. Drive does not */
  573.                                          /*   have to exist in drive list.  */
  574.    fileDialog.papszIDriveList = NULL;  /* Pointer to table of pointers that */
  575.                                        /*   point to null terminated Drive  */
  576.                                        /*   strings. End of table is marked */
  577.                                                       /* by a NULL pointer. */
  578.    fileDialog.hMod = (HMODULE)0;            /* Custom File Dialog template. */
  579.    strcpy(fileDialog.szFullFile, szFullPath); /* Initial or selected fully  */
  580.                                               /*   qualified path and file. */
  581.    fileDialog.papszFQFilename = NULL;  /* Pointer to table of pointers that */
  582.                                        /*   point to null terminated FQFname*/
  583.                                        /*   strings. End of table is marked */
  584.                                        /*   by a NULL pointer.              */
  585.    fileDialog.ulFQFCount = 0UL;                 /* Number of files selected */
  586.    fileDialog.usDlgId = IDD_FILESAVE;                  /* Custom dialog id. */
  587.    fileDialog.x = 0;                          /* X coordinate of the dialog */
  588.    fileDialog.y = 0;                          /* Y coordinate of the dialog */
  589.    fileDialog.sEAType = 0;                      /* Selected file's EA Type. */
  590.  
  591.  
  592.    /*
  593.     * Get the file
  594.     */
  595.    if (!WinFileDlg(HWND_DESKTOP, hwndMLE, (PFILEDLG)&fileDialog))
  596.       return FALSE;
  597.  
  598.    if (fileDialog.lReturn != ID_OK)
  599.       return FALSE;
  600.  
  601.    /*
  602.     * Copy file name and path returned into buffers
  603.     */
  604.    strcpy(szFullPath, fileDialog.szFullFile);
  605.  
  606.    return TRUE;
  607.  
  608. }   /* End of GetFileName() */
  609.  
  610.  
  611. /*********************************************************************
  612.  *  Name : UpdateTitleText
  613.  *
  614.  *  Description : Updates the text in the main window's title bar
  615.  *                to display the app name, followed by the
  616.  *                separator, followed by the file name
  617.  *
  618.  *  Concepts : Called at init time and when the text file is
  619.  *             changed gets the program name, appends the
  620.  *             separator, and appends the file name.
  621.  *
  622.  *  API's : WinQueryTaskTitle
  623.  *          WinLoadString
  624.  *          WinSetWindowText
  625.  *
  626.  *  Parameters : hwnd - handle of the main window
  627.  *
  628.  *  Returns : Void
  629.  *
  630.  ****************************************************************/
  631. VOID UpdateTitleText(HWND hwnd)
  632. {
  633.    CHAR szBuf[CCHMAXPATH + MAXNAMEL];
  634.    CHAR szSeparator[TITLESEPARATORLEN + 1];
  635.    PSZ pszTitle;
  636.  
  637.    WinQueryTaskTitle(0UL, szBuf, MAXNAMEL);
  638.  
  639.    WinLoadString(hab, NULLHANDLE, IDS_TITLEBARSEPARATOR, TITLESEPARATORLEN,
  640.                   szSeparator);
  641.  
  642.    strcat(szBuf, szSeparator);
  643.  
  644.    if (szFullPath[0] == '\0')
  645.       pszTitle = szUntitled;
  646.    else
  647.       pszTitle = szFullPath;
  648.  
  649.    strcat(szBuf, pszTitle);
  650.  
  651.    /***********************************************************************
  652.    * If title is longer that maximum allowable, show the most significant *
  653.    * portion of it (filename end of path).                                *
  654.    ***********************************************************************/
  655.    if (strlen(szBuf) + 1 > MAXNAMEL)
  656.       pszTitle = &szBuf[strlen(szBuf) - MAXNAMEL + 1];
  657.    else
  658.       pszTitle = szBuf;
  659.  
  660.    WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), pszTitle);
  661.    return;
  662. }          /*  End of UpdateTitleText()                                      */
  663.  
  664.  
  665. /***********************************************************
  666.  * Name         : OpenSaveFilterProc
  667.  *
  668.  * Description  : Procedure to handle wm_help messages for
  669.  *                the file open/save dialog.
  670.  *
  671.  * Concepts     : This routine handles the WM_HELP messages for
  672.  *                the dialog boxs created with the WinFileDlg
  673.  *                Checks the flags used on the call to determine
  674.  *                the correct help panel to display.
  675.  *
  676.  * API's        : WinQueryWIndowULong
  677.  *                WinSendMessage
  678.  *
  679.  * Parameters   : hwnd - Window handle to which message is addressed
  680.  *                msg - Message type
  681.  *                mp1 - First message parameter
  682.  *                mp2 - Second message parameter
  683.  *
  684.  *  Returns : Dependent upon message sent
  685.  **************************************************************/
  686. MRESULT APIENTRY OpenSaveFilterDlgProc(HWND hwnd, USHORT msg,
  687.                                        MPARAM mp1, MPARAM mp2)
  688. {
  689.    if(msg == WM_HELP)
  690.    {
  691.       /*
  692.        * Get a pointer to the file dialog structure.
  693.        */
  694.       PFILEDLG pOpenSaveFileDlgStruct = (PFILEDLG)WinQueryWindowULong(hwnd,
  695.                                                                      QWL_USER);
  696.  
  697.       /*
  698.        * If this is an the File Open dialog, display the file open help
  699.        * panel.
  700.        */
  701.       if (pOpenSaveFileDlgStruct->fl & FDS_OPEN_DIALOG)
  702.       {
  703.          DisplayHelpPanel(PANEL_FILEOPEN);
  704.          return (MRESULT)FALSE ;
  705.       }
  706.  
  707.       /*
  708.        * If this is an the File Save or Save As dialog, display the file
  709.        * Save As help panel.
  710.        */
  711.  
  712.       if (pOpenSaveFileDlgStruct->fl & FDS_SAVEAS_DIALOG)
  713.       {
  714.          DisplayHelpPanel(PANEL_FILESAVEAS);
  715.          return (MRESULT)FALSE ;
  716.       }
  717.    }
  718.    return WinDefFileDlgProc( hwnd, msg, mp1, mp2 );
  719. }                     /* End of OpenSaveFilterDlgProc  */
  720.  
  721.