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