    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Windows File Class</title>
        <link>https://members.accu.org/index.php/journals/1386</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">Overload Journal #3 - Aug 1993 + Programming Topics</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c225/">03</a>
                    (13)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c65/">Programming</a>
                    (877)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c225-65/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c225+65/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Windows File Class</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 01 August 1993 11:54:00 +01:00 or Sun, 01 August 1993 11:54:00 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<p>Requires Microsoft Windows 3.1.</p>
<p>This is an abstract class to support the saving and loading of the
contents of a window to a file (i.e. the New, Open, Save and Save As
options on the File menu). It uses the &quot;Open&quot; and &quot;Save As&quot; dialogs
from the Windows Common Dialog Box Library.</p>
<p><tt><b>CanDelete()</b></tt> controls whether
or not the object can be deleted without losing data. If the object has
changed since it was last saved, a message box is displayed asking if
the file should be saved and giving the options &quot;Yes&quot;, &quot;No&quot; and
&quot;Cancel&quot;.</p>
<p>If the user saves the file (<tt>CanDelete()</tt> calls <tt>SaveToFile()</tt>
to do this) or chooses not to save it, <tt>CanDelete()</tt>
returns TRUE. If the user cancels the message box or the &quot;Save As&quot;
dialog box (using the Cancel button or the Close option on the system
menu), <tt>CanDelete()</tt> returns FALSE.</p>
<p><tt><b>LoadFromFile()</b></tt> can be called
in response to the File|Open command. It asks the user to select a file
using the standard &quot;Open&quot; dialog box. It then opens the file and calls <tt>ReadFile()</tt>,
which must be defined in a derived class.</p>
<p><tt><b>CanDelete()</b></tt> should be called
before calling <tt>LoadFromFile()</tt>, to ensure that any changes
are not lost.</p>
<p><tt><b>SaveToFile()</b></tt> opens the file
associated with the object and calls <tt>WriteFile()</tt>
to write the object to the file. If no filename has yet been specified,
or if the 'prompt' parameter is TRUE (such as when File|Save As is
selected), this function requests one via the &quot;Save As&quot; common dialog
box.</p>
<p><tt><b>file_filter</b></tt> is the list of
file type descriptions passed to the Common Dialog Box routines to
specify which files should be shown in the list box. See the
description of the lpstrFilter field in the Windows OPENFILENAME
structure.</p>
<p><tt><b>default_extn</b></tt> is passed to
both the Open and Save dialog boxes for use if the user does not
specify a filename extension.</p>
<p><tt><b>HasChanged()</b></tt> is provided to allow a derived class to
flag that the object has changed and should therefore be saved before
being deleted. Note that the derived class is only allowed to set this
flag (not clear it).</p>
<pre>/*******************************************************<br>File:&nbsp;&nbsp; &nbsp;FILEDOBJ.H<br>*******************************************************/<br><br>class FILED_OBJECT<br>{<br>public:<br>  // Public read-only access to object's filename<br>  const char* const filename;<br>  BOOL CanDelete(char* app_name);<br>  BOOL LoadFromFile();<br>  BOOL SaveToFile(BOOL prompt); <br>protected:<br>  FILED_OBJECT(HWND h) : hwnd(h),<br>                         filename(filename_buf), <br>                         file_filter(NULL), <br>                         default_extn(NULL), <br>                         has_filename(FALSE),<br>                         has_changed(FALSE)<br>                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}<br>  HWND hwnd;<br>  char filename_buf[256];&nbsp; // Storage space for filename of object.<br>  char* file_filter;<br>  char* default_extn;<br>  void HasChanged() { has_changed = TRUE; } <br>private:<br>  BOOL has_filename;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Is filename set up yet?<br>  BOOL has_changed;<br>  virtual void ReadFile(HFILE f) = 0;<br>  virtual void WriteFile(HFILE f) = 0; <br>};<br><br>/*******************************************************<br>File:&nbsp;&nbsp; &nbsp;FILEDOBJ.CPP<br>Description:<br>This file contains the definition of the FILED_OBJECT<br>class described in the header file FILEDOBJ.H.<br>*******************************************************/<br>#include &lt;windows.h&gt; <br>#include &lt;commdlg.h&gt; <br>#include &quot;filedobj.h&quot;<br><br>/*======================================================<br>Function:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CanDelete() <br>Parameters:<br>app_name - string to be used as title of message box.<br>Description:<br>This function is designed to be called before any operation <br>that will lose the object's data - e.g. selecting File|New, <br>File|Open or quitting from the application.<br><br>We make use of the 'has_changed' flag to determined <br>whether there are any outstanding changes. This flag is <br>cleared when the object is saved to or loaded from a file<br>and should be set by the derived class when the object <br>changes (by calling HasChanged()).<br><br>If the file HAS changed, we put up a message box allowing <br>the user to save the changes, abandon the changes or <br>cancel the operation. To save the changes we call <br>SaveToFile().<br><br>Return value:<br>If the object hasn't changed, the user doesn't want to<br>save the changes, or the changes are saved successfully, <br>we return TRUE - i.e. the object CAN be deleted. <br>Otherwise (i.e. the user selects cancel or the file can't<br>be saved), we return FALSE - the object CAN'T be deleted.<br>======================================================*/<br><br>BOOL FILED_OBJECT::CanDelete(char* app_name) <br>{<br>  if (!has_changed) return TRUE; // No need to save the object<br><br>  // Find the actual filename (first char after last backslash)<br>  // Start at the end...and look backwards<br>  for (char* name = filename_buf; *name; ++name)<br>    while (name != fiIename_buf &amp;&amp; name[-1] != '\\') <br>	--name;<br><br>  char msg[80];<br>  wsprintf(msg, <br>           &quot;%s has changed.\nDo you want to save the changes?&quot;,<br>          (LPSTR)name);<br>  MessageBeep(MB_ICONQUESTION); <br>  switch (MessageBox(hwnd, msg, <br>                     app_name,MB_ICONQUESTION|MB_YESNOCANCEL))<br>  {<br>    case IDYES :<br>      return SaveToFile(FALSE); // Can delete if saved OK<br>    case IDNO :<br>      return TRUE; // Yes - you can delete me <br>    case IDCANCEL : <br>    default :<br>      return FALSE; // No - don't you dare! <br>  }<br>}<br><br>/*======================================================<br>Function:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LoadFromFile()<br>Description:<br>Using the common 'Open' dialog box, this function <br>prompts the user for the file that is to be opened, <br>opens the file and calls ReadFile() to read the object <br>from the file. The file is then closed.<br><br>Note that the user may only select an existing, writeable<br>file. We should therefore have no problems reading or <br>(later) writing the file.<br><br>Return value:<br>This function returns TRUE (i.e. 'success') if the file <br>is read OK, FALSE if the user cancelled from the 'Open' <br>dialog box.<br><br>Notes:<br>A temporary buffer is used to receive the new filename <br>so that we don't overwrite the current filename unless <br>a new one is successfully chosen.<br>======================================================*/<br>BOOL FILED OBJECT::LoadFromFile()<br>{<br>  OPENFILENAME ofn;<br>  char new_name[sizeof filename_buf];<br>  new_name[0] = 0;<br>  ofn.lStructSize = sizeof(OPENFILENAME);<br>  ofn.hwndOwner = hwnd;<br>  ofn.ipstrFilter = file_filter;<br>  ofn.lpstrCustomFilter = NULL;<br>  ofn.nFilterIndex = 1;<br>  ofn.IpstrFile = new_name;<br>  ofn.nMaxFile = sizeof new_name;<br>  ofn.lpstrFileTitle = NULL;<br>  ofn.lpstrInitialDir = NULL; // Use default directory<br>  ofn.lpstrTitle = NULL;<br>  ofn.Flags = OFN_FILEMUSTEXIST |<br>              OFN__NOREADONLYRETURN | <br>              OFN_HIDEREADONLY; // Extn: allow read-only<br>  ofn.lpstrDefExt = default_extn;<br><br>  if (!GetOpenFileName(&amp;ofn)) return FALSE;<br><br>  OFSTRUCT info;  // Extn: share flags?, failure?<br><br>  HFILE f = OpenFile(new_name, &amp;info, OF_READ);<br><br>  ReadFile(f); // Extn: handle failure (e.g. incorrect format)<br>  _lclose(f);<br><br>  lstrcpy(fiIename_buf,&nbsp; new_name); <br>  has_filename = TRUE; <br>  has__changed = FALSE; <br>  return TRUE;<br>}<br><br>/*======================================================<br>Function:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SaveToFile{}<br>Parameters:<br>prompt - If FALSE, only asks user for a filename if the<br>object doesn't already have one; if TRUE, asks for one<br>regardless.<br><br>Description:<br>This function opens the file associated with the object<br>(or selected by the user if 'prompt' is TRUE of the <br>object has no filename yet), calls WriteFile() to write <br>the object to the file and then closes the file.<br><br>If 'prompt' is TRUE and a filename already exists (e.g. <br>the user selected 'Save As' from the menu), the current <br>filename is displayed as the default.<br><br>Return value:<br>This function returns TRUE (i.e. 'success') if the file <br>is saved OK, FALSE if the user cancelled from the <br>'Save As' dialog box.<br>======================================================*/<br><br>BOOL FILED_OBJECT::SaveToFile(BOOL prompt) <br>{<br>  OPENFILENAME ofn;<br><br>  if (prompt || !has_filename) // Get filename from user <br>  {<br>    char new_name[sizeof filename_buf];<br>    lstrcpy(new_name, filename);<br>    ofn.lStructSize = sizeof(OPENFILENAME);<br>    ofn.hwndOwner = hwnd;<br>    ofn.ipstrFilter = file_filter;<br>    ofn.lpstrCustomFilter = NULL;<br>    ofn.nFilterIndex = 1;<br>    ofn.lpstrFile = new_name;<br>    ofn.nMaxFile = sizeof new_name;<br>    ofn.lpstrFileTitle = NULL;<br>    ofn.lpstrInitialDir = NULL; // Use default directory<br>    ofn.lpstrTitle = NULL;<br>    ofn.Flags = OFN_NOREADONLYRETURN |<br>                OFN_HIDEREADONLY | <br>                OFN_OVERWRITEPROMPT;<br>    ofn.lpstrDefExt = default_extn;<br>    if (!GetSaveFileName(&amp;ofn)) return FALSE;<br>    lstrcpy(filename_buf, new_name); has_filename = TRUE; <br>  }<br><br>  OFSTRUCT info; // Extn: share flags?, failure?<br> &nbsp;HFILE f = OpenFile(filename_buf, &amp;info, <br>                     OF_WRITE|OF_CREATE);<br>  <br>  WriteFile(f);<br>  _lclose(f);<br><br>  has_changed = FALSE; <br>  return TRUE; <br>}<br><br></pre>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
