⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 178-182.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:

		</td>
		
<!-- PUB PARTNERS END -->
<!-- END LEFT NAV -->

<td rowspan="8" align="right" valign="top"><img src="/images/iswbls.gif" width=1 height=400 alt="" border="0"></td>
<td><img src="/images/white.gif" width="5" height="1" alt="" border="0"></td>
<!-- end of ITK left NAV -->

<!-- begin main content -->
<td width="100%" valign="top" align="left">


<!-- 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="">&nbsp;<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=178-182//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="174-178.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="182-184.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading11"></A><FONT COLOR="#000077">Copying and Renaming Files and Directories</FONT></H3>
<P>Files and directories on Windows CE&#150;based devices, much like their counterparts on Windows NT, are often used by users of the devices to organize data and documents. Let&#146;s say that you are writing a specification (on your Handheld PC, of course!) for a new suite of Windows CE applications. This specification might consist of several files, such as functional and design specifications for each application in the suite.
</P>
<P>If you are like most of us, the organization of this specification will change as your understanding of the required behavior of the applications you are designing evolves. Therefore, the locations and names of the files that make up your application suite specification are unlikely to be the same when the specification is complete as they were when the files were created.</P>
<P>Copying files and directories, renaming them, and moving them around in a directory tree are all very common file operations. Windows CE supports these operations with the <I>CopyFile</I> and <I>MoveFile</I> functions. The <I>MoveFileEx</I> function found in Windows NT is not supported under Windows CE.</P>
<P><FONT SIZE="+1"><B>The <I>CopyFile</I> Function
</B></FONT></P>
<P>Copying a file in Windows CE simply requires that an application know the name of the file to be copied and the name of the file to which it is to be copied:
</P>
<!-- CODE SNIP //-->
<PRE>
  CopyFile(lpExistingFileName, lpNewFileName, bFailIfExist);
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>lpExistingFileName</I> parameter contains the null-terminated string name of the file to be copied. <I>lpNewFileName</I> is the name of the file to which <I>CopyFile</I> copies the original file.</P>
<P><I>bFailIfExist</I> tells <I>CopyFile</I> what to do if a file named <I>lpNewFileName</I> already exists. If this parameter is TRUE and the new file already exists, <I>CopyFile</I> fails and returns FALSE. If <I>bFailIfExist</I> is FALSE in this same scenario, <I>CopyFile</I> does not fail. In this case it overwrites the existing file named <I>lpNewFileName</I>.</P>
<P>Another effect of copying a file is that all of the attributes (FILE_ATTRIBUTE_HIDDEN, etc.) of the file are copied to the new file.</P>
<P><FONT SIZE="+1"><B>The <I>MoveFile</I> Function
</B></FONT></P>
<P>At first glance, the <I>MoveFile</I> function seems to have been inappropriately named. <I>MoveFile</I> actually <I>renames</I> files and directories in the Windows CE file system. It might seem that <I>RenameFile</I> would be a more accurate name for this function.</P>
<P>In the case of renaming files, that might be correct. But consider the case of renaming a directory. Let&#146;s take the example of a Windows CE directory called MyFiles. When an application renames this directory to MyOldFiles, for example, all of the <I>children</I> of this directory are renamed accordingly as well. More specifically, all files and subdirectories that MyFiles contains have their path names changed to reflect the fact that MyFiles has changed to MyOldFiles (Figure 6.9). From this point of view, it&#146;s as if the <I>MoveFile</I> operation physically moved all the children of MyFiles to a new directory called MyOldFiles.</P>
<P><A NAME="Fig13"></A><A HREF="javascript:displayWindow('images/06-13.jpg',640,320 )"><IMG SRC="images/06-13t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-13.jpg',640,320)"><FONT COLOR="#000077"><B>Figure 6.9</B></FONT></A>&nbsp;&nbsp;Effect of renaming a directory on its children.</P>
<P>The syntax of the <I>MoveFile</I> function is:</P>
<!-- CODE SNIP //-->
<PRE>
  MoveFile(lpExistingFileName, lpNewFileName);
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>lpExistingFileName</I> and <I>lpNewFilename</I> parameters are the same as in the <I>CopyFile</I> function: <I>lpExistingFileName</I> is the name of the file or directory to be renamed, and <I>lpNewFileName</I> is the name to which the file or directory is renamed.</P>
<P>If <I>MoveFile</I> is successful, it returns TRUE. If the function fails, it returns FALSE. In that case, an application can call <I>GetLastError</I> to get more information about what went wrong. For example, if an application attempts to rename a file to the name of a file that already exists, <I>GetLastError</I> would return ERROR_ALREADY_EXISTS.</P>
<H3><A NAME="Heading12"></A><FONT COLOR="#000077">Deleting Files and Directories</FONT></H3>
<P>Deleting a file in Windows CE is a simple matter of calling <I>DeleteFile</I>:</P>
<!-- CODE SNIP //-->
<PRE>
  DeleteFile(lpFileName);
</PRE>
<!-- END CODE SNIP //-->
<P>Your application calls this function by passing the full path name of the file to be deleted in the <I>lpFileName</I> parameter.</P>
<P>If the file is deleted, <I>DeleteFile</I> returns TRUE. Otherwise, it will return FALSE, in which case you can call <I>GetLastError</I> for more information.</P>
<P>Similarly, directories are deleted using <I>RemoveDirectory</I>:</P>
<!-- CODE SNIP //-->
<PRE>
  RemoveDirectory(lpPathName);
</PRE>
<!-- END CODE SNIP //-->
<P><I>lpPathName</I> is the full path name of the directory to be removed. <I>RemoveDirectory</I> has the same return values as <I>DeleteFile</I>.</P>
<P><I>RemoveDirectory</I> will fail if an application attempts to delete a directory that is not empty. There is no parameter to force deletion of an empty directory, or to do recursive deletion of an entire directory tree. Such functionality, if required by an application, must be implemented by the application developer. The File System Explorer sample application shows how this is done with its implementation of the <I>OnDelete</I> function.</P>
<H3><A NAME="Heading13"></A><FONT COLOR="#000077">Flash Cards and Persistent Storage</FONT></H3>
<P>Flash memory cards provide a means for Windows CE&#150;based devices to expand the amount of RAM available. A flash card is a type of <I>mountable file system</I>. Both Handheld PCs and Palm-size PCs are equipped to use flash cards. Flash cards can be used to store files just like regular RAM.</P>
<P>Flash cards are assigned object identifiers just like files or directories. We will see some examples of how these identifiers are used in the next section.</P>
<P>Flash cards should include a \My Documents folder. Many of the mountable file system API functions will default to such a folder to perform searches and the like.</P>
<P>To the Windows CE device, a flash card looks like part of the file system. A flash card installed on a Palm-size PC or Handheld PC is assigned the folder name Storage Card by the operating system. Files and directories are created and accessed just as they are in standard RAM using the file system API. The only difference is that the path names of flash card files and directories begin with Storage Card.</P>
<P>For example, to create a directory called &#147;FlashDocs&#148; on a Palm-size PC storage card, an application would simply call <I>CreateDirectory</I>:</P>
<!-- CODE SNIP //-->
<PRE>
  CreateDirectory(TEXT("\\Storage Card\\FlashDocs"), NULL);
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="174-178.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="182-184.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>&nbsp;|&nbsp; <a href="/contactus.html"><font color="#006666">Contact Us</font></a>&nbsp;|&nbsp; <a href="/aboutus.html"><font color="#006666">About Us</font></a>&nbsp;|&nbsp; <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> &nbsp;|&nbsp; <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> &nbsp;|&nbsp; <a href="/"><font color="#006666">Home</font></a></b>
		<br><br>
		
		Use of this site is subject to certain <a href="/agreement.html">Terms &amp; Conditions</a>, <a href="/copyright.html">Copyright &copy; 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 + -