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

📄 201-204.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- 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=7//-->
<!--PAGES=201-204//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="199-201.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="204-207.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Opening and Closing the Database</FONT></H3>
<P>Not surprisingly, the function that is used to open a Windows CE database is called <I>CeOpenDatabase</I>:</P>
<!-- CODE SNIP //-->
<PRE>
   CeOpenDatabase(poid, lpszName, propid, dwFlags, hwndNotify);
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>poid</I> argument is the object identifier of the database to open. Alternatively (and more commonly), you will open a database by name. This is done by setting the <I>poid</I> argument to zero, and supplying the name of the database to open in the <I>lpszName</I> argument. If a database is opened in this way, Windows CE will return the object identifier of the database via the <I>poid</I> argument.</P>
<P>The <I>propid</I> argument is a CEPROPVAL that specifies which sort order to use when sorting the database. <I>dwFlags</I> can be set to CEDB_ AUTOINCREMENT, or to zero. If set to CEDB_AUTOINCREMENT, the database record pointer is incremented each time a record is read from the database. If zero, the record pointer is not incremented.</P>
<P>The <I>hwndNotify</I> parameter can be used to specify the window to which database notifications are sent. It can be NULL if you are not interested in receiving such notifications. Database notifications are discussed later in the chapter.</P>
<P><I>CeOpenDatabase</I> returns a handle to the opened database if successful. Otherwise it returns the error code INVALID_HANDLE_VALUE.</P>
<P>To close a database, use the function <I>CloseHandle</I>, passing the handle to the open database as the <I>hObject</I> parameter.</P>
<P>From the point of view of database sorting, the <I>propid</I> argument to <I>CeOpenDatabase</I> gets all the glory. An application specifies how the database is sorted simply by calling <I>CeOpenDatabase</I> with the desired sorting property specified in the <I>propid</I> parameter. For example, to sort the records in the phone list database by first name, our application simply needs to open the database as follows:</P>
<!-- CODE SNIP //-->
<PRE>
   CEOID ceoidDBase=0;  //0 because we will open the database
               //by name
   CeOpenDatabase(ceoidDBase, TEXT("PhoneList"), PL_FIRSTNAME,
     CEDB_AUTOINCREMENT, NULL);
</PRE>
<!-- END CODE SNIP //-->
<P>If the application already has the database open when it wants to resort it on a new key, it must first close the database with <I>CloseHandle</I> before reopening it.</P>
<P><FONT SIZE="+1"><B>Writing an <I>OpenDatabase</I> Function
</B></FONT></P>
<P>You may often find it convenient to combine the processes of creating and opening a database into one function. Consider the following <I>OpenDatabase</I> function:</P>
<!-- CODE //-->
<PRE>
   HANDLE OpenDatabase(
     LPWSTR lpszName,    /* Database name */
     CEPROPID cepropidSort, /* Sort property */
     DWORD dwFlags,     /*CEDB_AUTOINCREMENT,etc.*/
     HWND hwndNotify,
     CEOID* pceoid)     /*CEOID of opened database*/
   &#123;
     HANDLE hdb;
     *pceoid = 0;
     hdb = CeOpenDatabase(pceoid, lpszName,
      cepropidSort, dwFlags, hwndNotify);
     if (INVALID_HANDLE_VALUE==hdb)
     &#123;
      SORTORDERSPEC sos[4];
      sos[0].propid = PL_LASTNAME;
      sos[0].dwFlags = 0;
      sos[1].propid = PL_FIRSTNAME;
      sos[1].dwFlags = 0;
      sos[2].propid = PL_PHONENUMBER;
      sos[2].dwFlags = 0;
      sos[3].propid = PL_DEPT;
      sos[3].dwFlags = 0;
      ceoidDBase = CeCreateDatabase(szDBaseName,0, 4, sos);
     hdb = CeOpenDatabase(pceoid, NULL,cepropidSort,
      CEDB_AUTOINCREMENT, hwndNotify);
     &#125;
     return (hdb);
   &#125;
</PRE>
<!-- END CODE //-->
<P>One advantage of such a function is that once the function is written, the application programmer can think of creating and opening the database as the same operation. Instead of having to consider whether or not the database exists, the programmer can simply call this <I>OpenDatabase</I> function. If it happens to be the first time that the database is being accessed and it doesn&#146;t yet exist, this function will create the database.</P>
<H3><A NAME="Heading8"></A><FONT COLOR="#000077">Writing and Reading Database Records</FONT></H3>
<P>We have seen how to create, open, close, and sort the records in a database. But how do the records get into the database to begin with? And how are the records retrieved by an application that needs to use the information that these records contain?
</P>
<P>Writing records to a database requires our old friend the CEPROPVAL structure and the <I>CeWriteRecordProps</I> function. Basically, an application fills an array of CEPROPVALs with the property information for the record, and then calls <I>CeWriteRecordProps</I> to actually write the record to the database. For example, to write a hypothetical record to the phone list database, the phone list application might do something like this:</P>
<!-- CODE //-->
<PRE>
   CEPROPVAL cePropVal[4];
   //Set the last name
   cePropVal[PL_LASTNAME_INDEX].propid = PL_LASTNAME;
   cePropVal[PL_LASTNAME_INDEX].val.lpwstr = TEXT("Rubble");
   //Set the first name
   cePropVal[PL_FIRSTNAME_INDEX].propid = PL_FIRSTNAME;
   cePropVal[PL_FIRSTNAME_INDEX].val.lpwstr = TEXT("Barney");
   //Set the phone number
   cePropVal[PL_PHONENUMBER_INDEX].propid = PL_PHONENUMBER;
   cePropVal[PL_PHONENUMBER_INDEX].val.lpwstr = TEXT("888-8888");
   //Set the department id
   cePropVal[PL_DEPT_INDEX].propid = PL_DEPT;
   cePropVal[PL_DEPT_INDEX].val.iVal = 12;
   CeWriteRecordProps(hDBase, 0, 4, cePropVal);
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="199-201.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="204-207.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 + -