📄 159-162.html
字号:
<!-- END SUB HEADER -->
<!--Begin Content Column -->
<FONT FACE="Arial,Helvetica" SIZE="-1">
To access the contents, click the chapter and section titles.
</FONT>
<P>
<B>Essential Windows CE Application Programming</B>
<FONT SIZE="-1">
<BR>
<I>(Publisher: John Wiley & Sons, Inc.)</I>
<BR>
Author(s): Robert Burdick
<BR>
ISBN: 0471327476
<BR>
Publication Date: 03/01/99
</FONT>
<P>
<form name="Search" method="GET" action="http://search.earthweb.com/search97/search_redir.cgi">
<INPUT TYPE="hidden" NAME="Action" VALUE="Search">
<INPUT TYPE="hidden" NAME="SearchPage" VALUE="http://search.earthweb.com/search97/samples/forms/srchdemo.htm">
<INPUT TYPE="hidden" NAME="Collection" VALUE="ITK">
<INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="itk-simple-intrabook.hts">
<INPUT TYPE="hidden" NAME="ViewTemplate" VALUE="view.hts">
<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="queryText" size=50 VALUE=""> <input type="submit" name="submitbutton" value="Go!">
<INPUT type=hidden NAME="section_on" VALUE="on">
<INPUT type=hidden NAME="section" VALUE="http://www.itknowledge.com/reference/standard/0471327476/">
</form>
<!-- Empty Reference Subhead -->
<!--ISBN=0471327476//-->
<!--TITLE=Essential Windows CE Application Programming//-->
<!--AUTHOR=Robert Burdick//-->
<!--PUBLISHER=John Wiley & Sons, Inc.//-->
<!--IMPRINT=Wiley Computer Publishing//-->
<!--CHAPTER=6//-->
<!--PAGES=159-162//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="153-159.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="162-165.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
</P>
<P><FONT SIZE="+1"><B>Editing Files</B></FONT></P>
<P>Another important set of file system functions we will cover in this chapter lets your applications write data to and read data from files. To demonstrate these features, the File System Explorer application provides very rudimentary file editing capabilities. You will not be tempted to delete your current word processing software from your Handheld PC when you see this feature. However, after finishing this chapter you will know how to use the file system API to read and write files.
</P>
<P>To edit a file in the FILESYS.EXE application, select the file you wish to edit by tapping it once. Then press the Enter key on your keyboard. (For devices that do not include a keyboard, you can use the Edit File menu option in the Options menu to invoke this feature.) The dialog box shown in Figure 6.7 appears.</P>
<P><A NAME="Fig11"></A><A HREF="javascript:displayWindow('images/06-11.jpg',480,240 )"><IMG SRC="images/06-11t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-11.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 6.7</B></FONT></A> Editing a file with the file system explorer.</P>
<P>Text entered in the edit field of this dialog is written to the file if the user presses the Save button. Pressing Cancel aborts file editing.
</P>
<P><FONT SIZE="+1"><B>Examining File Properties</B></FONT></P>
<P>The final notable feature of the File System Explorer application is invoked by the Properties option of the Option menu. Choosing this menu option retrieves and displays various features of the currently selected file. The dialog box shown in Figure 6.8 appears, showing which file attributes are set for the selected file, as well as the size of the file in bytes.
</P>
<P><A NAME="Fig12"></A><A HREF="javascript:displayWindow('images/06-12.jpg',480,240 )"><IMG SRC="images/06-12t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-12.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 6.8</B></FONT></A> Displaying the properties of a file.</P>
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">File Handles</FONT></H3>
<P>The Windows CE file system API functions access files and directories by means of a <I>file handle</I>. Like any other Windows CE handle type, such as a window handle, a file handle is an identifier for referencing an object managed by the Windows CE kernel. In this case the object is a file or directory.</P>
<P>As we will see, the function used for opening and creating files returns a handle to the specified file. Functions for reading and writing files require a file handle in order to access the right file. In short, any operation that a Windows CE application may perform on a file or directory requires a valid file handle.</P>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">File Attributes</FONT></H3>
<P>Every file in the Windows CE file system has one or more <I>attributes</I>. These attributes are used to distinguish files in terms of characteristics such as how they can be used and by whom. Under Windows CE, files may have one or more of the attributes listed in Table 6.1.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 6.1</B> Windows CE File Attributes
<TR>
<TH WIDTH="40%" ALIGN="LEFT">ATTRIBUTE
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD VALIGN="TOP">FILE_ATTRIBUTE_ARCHIVE
<TD>Used by applications to mark a file that has not been backed up.
<TR>
<TD VALIGN="TOP">FILE_ATTRIBUTE_COMPRESSED
<TD>File or directory is compressed. For files, this means that all of the data in the file is compressed. For directories, this means that by default all files or subdirectories created in this directory are created with the compressed attribute.
<TR>
<TD>FILE_ATTRIBUTE_HIDDEN
<TD>The file is marked as hidden.
<TR>
<TD VALIGN="TOP">FILE_ATTRIBUTE_NORMAL
<TD>This attribute cannot be used with any other attribute. Hence, if set, it means that no other attribute is set.
<TR>
<TD VALIGN="TOP">FILE_ATTRIBUTE_READONLY
<TD>Applications can only read this file. They cannot write to or delete it.
<TR>
<TD VALIGN="TOP">FILE_ATTRIBUTE_DIRECTORY
<TD>Indicates that the particular file is a directory. Note: This attribute cannot be set. It can be returned by GetFileAttributes.
<TR>
<TD VALIGN="TOP">FILE_ATTRIBUTE_SYSTEM
<TD>Indicates the file is a system file, i.e., it is intended to be used only by the operating system.
<TR>
<TD VALIGN="TOP">FILE_ATTRIBUTE_INROM
<TD>Indicates the file is a read-only operating system file stored in ROM.
<TR>
<TD>FILE_ATTRIBUTE_ROMMODULE
<TD>Indicates the file is an in-ROM DLL or EXE.
</TABLE>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B><B>F<SMALL>ILE</SMALL> A<SMALL>TTRIBUTES</SMALL></B>
<P><B>Under Windows CE, the FILE_ATTRIBUTE_OFFLINE and FILE_ATTRIBUTE_TEMPORARY file attributes are not supported.</B><HR></FONT>
</BLOCKQUOTE>
</P>
<P>An application typically sets the attributes of a file when the file is created. However, it may be necessary to change or determine the attributes of a file after it has been created. Applications might even need to determine the attributes of files they did not create.</P>
<P>The Windows CE file system API provides two functions to read and modify the attributes of a file, <I>GetFileAttributes</I> and <I>SetFileAttributes</I>. The first of these functions has the following form:</P>
<!-- CODE SNIP //-->
<PRE>
GetFileAttributes(lpFileName);
</PRE>
<!-- END CODE SNIP //-->
<P>This function takes the Unicode string name of the file of interest in the parameter <I>lpFileName</I>. If successful, it returns a DWORD containing the file attributes that are set for the file. The return value is the bit-wise OR of one or more of the file attribute values specified in Table 6.1. In addition, Windows CE provides for two additional return values for this function, FILE_ATTRIBUTE_INROM and FILE_ATTRIBUTE_ROMMODULE. The first of these indicates that the file in question is a read-only operating system file stored in ROM. The second indicates that the file is a DLL or executable (.EXE) file stored in ROM and intended to execute in place. This means that files with the FILE_ATTRIBUTE_ROMMODULE attribute do not need to be copied into RAM in order to run. Files of this type are typically libraries and applications that ship with the Windows CE operating system.</P>
<P>The attributes of a file can be set using the <I>SetFileAttributes</I> function:</P>
<!-- CODE SNIP //-->
<PRE>
SetFileAttributes(lpFileName, dwFileAttributes);
</PRE>
<!-- END CODE SNIP //-->
<P>This function returns TRUE if the attributes are successfully set, and FALSE if the function is unsuccessful.
</P>
<P>As an example, let’s assume that we want to mark as hidden all files that are read-only. The piece of code responsible for testing if a file is read-only and then setting the hidden file attribute would look something like this:</P>
<!-- CODE SNIP //-->
<PRE>
//File name is in lpFileName
DWORD dwAttributes;
dwAttributes = GetFileAttributes(lpFileName);
if (dwAttributes & FILE_ATTRIBUTE_READONLY)
{
dwAttributes |= FILE_ATTRIBUTE_HIDDEN;
SetFileAttributes(lpFileName, dwAttributes);
}
</PRE>
<!-- END CODE SNIP //-->
<P>Note that as in Windows NT and Windows 98, <I>SetFileAttributes</I> cannot be used to set the FILE_ATTRIBUTE_COMPRESSED attribute of a file. If this attribute is not set when the file is created, you must use the <I>DeviceIoControl</I> function to set it.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="153-159.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="162-165.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<!-- all of the reference materials (books) have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- BEGIN SUB FOOTER -->
<br><br>
</TD>
</TR>
</TABLE>
<table width="640" border=0 cellpadding=0 cellspacing=0>
<tr>
<td align="left" width=135><img src="/images/white.gif" width=100 height="1" alt="" border="0"></td>
<!-- END SUB FOOTER -->
<!-- all of the books have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- FOOTER -->
<td width="515" align="left" bgcolor="#FFFFFF">
<font face="arial, helvetica" size="1"><b><a href="/products.html"><font color="#006666">Products</font></a> | <a href="/contactus.html"><font color="#006666">Contact Us</font></a> | <a href="/aboutus.html"><font color="#006666">About Us</font></a> | <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> | <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> | <a href="/"><font color="#006666">Home</font></a></b>
<br><br>
Use of this site is subject to certain <a href="/agreement.html">Terms & Conditions</a>, <a href="/copyright.html">Copyright © 1996-1999 EarthWeb Inc.</a><br>
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.</font><p>
</td>
</tr>
</table>
</BODY>
</HTML>
<!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -