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

📄 199-201.html

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

<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=7//-->
<!--PAGES=199-201//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="196-198.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="201-204.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">Sorting and the SORTORDERSPEC</FONT></H3>
<P>Applications sort databases by specifying up to four <I>sort orders</I>. A sort order specifies which property in each database record is to be used as the sorting key, and the order (ascending, descending, etc.) in which the database records are to be sorted when the corresponding property is used as the sorting key. This information can be provided to the database in one of two ways. The first is to pass this sort order information to the database when it is created via the last argument to the <I>CeCreateDatabase</I> function, <I>rgSortSpecs</I>. The second is to use the <I>CeSetDatabaseInfo</I> function and specify the sort orders in a CEDBASEINFO structure. To use either of these techniques, we must first understand how a sort order is represented in Windows CE.</P>
<P>A sort order is defined using the SORTORDERSPEC structure, which is defined as:</P>
<!-- CODE SNIP //-->
<PRE>
   typedef struct _SORTORDERSPEC
   &#123;
     CEPROPID propid;
     DWORD dwFlags;
   &#125; SORTORDERSPEC;
</PRE>
<!-- END CODE SNIP //-->
<P>The first member of this structure is the property identifier of a particular record property. The second member contains sort order flags. These flags define, for example, whether records are sorted in ascending or descending order.
</P>
<P>As an example, let&#146;s assume that we want to be able to sort the phone list database by last name in ascending order, and at other times to sort by department number in descending order. We would therefore need to define two SORTORDERSPEC structures to convey this information:</P>
<!-- CODE SNIP //-->
<PRE>
   SORTORDERSPEC sos[2];
   sos[0].propid = PL_LASTNAME;   //Specify the last name
                    //property id
   sos[0].dwFlags = 0;       //0 indicates ascending order
   sos[1].propid = PL_DEPT;     //Specify the deparment number
                    //property id
   sos[1].dwFlags = CEDB_SORT_DESCENDING; //Descending sort order
</PRE>
<!-- END CODE SNIP //-->
<P>Note the value of 0 for the <I>dwFlags</I> member of <I>sos</I>[0] to indicate ascending sort order. I point this out to save you the same amount of time I wasted searching in vain for a definition of CEDB_SORT_ASCENDING in the Windows CE header files.</P>
<P>Now that we understand how to specify a sort order, we are ready to discuss the two techniques for supplying the database with our sort order information. The first is to pass the array of SORTORDERSPEC structures that you create as the <I>rgSortSpecs</I> parameter of the <I>CeCreateDatabase</I> function. This would seem to imply that once a database is created, an application has no control over redefining the sort order information associated with that database. This is not the case, however. The second technique for specifying sort orders is with the <I>CeSetDatabaseInfo</I> function. The syntax of this function is:</P>
<!-- CODE SNIP //-->
<PRE>
   CeSetDatabaseInfo(oidDbase, pNewInfo);
</PRE>
<!-- END CODE SNIP //-->
<P>The first parameter of <I>CeSetDatabaseInfo</I> is the object identifier of an open database. The second parameter is a pointer to a CEDBASEINFO structure. This structure is defined as:</P>
<!-- CODE //-->
<PRE>
   typedef struct _CEDBASEINFO
   &#123;
     DWORD dwFlags;
     WCHAR szDbaseName[CEDB_MAXDBASENAMELEN];
     DWORD dwDbaseType;
     WORD wNumRecords;
     WORD wNumSortOrder;
     DWORD dwSize;
     FILETIME ftLastModified;
     SORTORDERSPEC rgSortSpecs[CEDB_MAXSORTORDER];
   &#125; CEDBASEINFO;
</PRE>
<!-- END CODE //-->
<P><I>szDbaseName</I> and <I>dwDbaseType</I> are the name and application-defined database type identifier respectively. <I>dwSize</I> is used by <I>CeSetDatabaseInfo</I> to return the number of bytes of data stored in the database. <I>ftLastModified</I> is used to update the time the database was last modified. The <I>wNumRecords</I> field is not used.</P>
<P>That leaves <I>dwFlags</I>, <I>wNumSortOrder</I>, and <I>rgSortSpecs</I>. <I>wNumSortOrder</I> specifies the new total number of sort orders associated with the database. Remember, Windows CE databases only support up to four sort orders. <I>rgSortSpecs</I> is our trusty array of SORTORDERSPEC structures. If you originally created the database with one set of sort orders, you can specify totally different sort orders here.</P>
<P>Finally, the <I>dwFlags</I> member is used to indicate to <I>CeSetDatabaseInfo</I> which of the other CEDBASEINFO structure members are valid, that is, which characteristics of the database are to be changed by the <I>CeSetDatabaseInfo</I> call. <I>dwFlags</I> can be one of the four values given in Table 7.3.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 7.3</B> CEDBASEINFO <I>dwFlags</I> Member Values
<TR>
<TH WIDTH="40%" ALIGN="LEFT">VALUE
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD>CEDB_VALIDMODTIME
<TD>ftLastModified member is valid
<TR>
<TD>CEDB_VALIDNAME
<TD>szDbaseName member is valid
<TR>
<TD>CEDB_VALIDTYPE
<TD>dwDbaseType member is valid
<TR>
<TD>CEDB_VALIDSORTSPEC
<TD>rgSortSpecs member is valid
</TABLE>
<P>It should be noted here that using <I>CeSetDatabaseInfo</I> to change the sort order of a database can be a very slow operation for Windows CE to perform, especially if the database being modified contains a large number of records. It is therefore not generally recommended that this be done. The sort order requirements for a particular database should instead be carefully considered and defined during the application design phase. The sort orders can then be set once and for all when the database is created.</P>
<P>Careful readers who have suffered through this laborious account of how and when to define database sort orders will have noticed that a huge piece of the sorting story is still missing. We have yet to discuss how a Windows CE database is told on which of the properties associated with the various sort orders the database is to be sorted. This is done, mercifully simply, by simply opening the database.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="196-198.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="201-204.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 + -