📄 211-214.html
字号:
<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=""> <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=211-214//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="209-211.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="214-216.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading10"></A><FONT COLOR="#000077">Database Enumeration</FONT></H3>
<P>Suppose you wanted to create a list of all the databases currently contained in the object store of a Windows CE device. Or perhaps you need to determine how much object store memory is being used by all the phone list databases available to a phone list management application. In this section we introduce the concept of <I>database enumeration</I>. Database enumeration allows applications to find all databases in the object store, or to find a subset of those databases as defined by a particular database type identifier.</P>
<P>Back when we discussed creating Windows CE databases, we introduced the concept of a database type identifier. This was the application-defined index that was passed as the <I>dwDbaseType</I> parameter of <I>CeCreateDatabase</I>. This index is used to identify all databases of a particular type. This type index is very important to database enumeration operations.</P>
<P>Database enumeration is done with two functions: <I>CeFindFirstDatabase</I> and <I>CeFindNextDatabase</I>. The enumeration process starts with a call to <I>CeFindFirstDatabase</I> to open an <I>enumeration context</I> for the type of database to be enumerated. The enumeration context is a handle through which the operating system can reference all databases with a particular database type identifier. <I>CeFindNextDatabase</I> is then called repeatedly to get the object identifier of each database of that type. These functions are analogous to the file system functions <I>FindFirstFile</I> and <I>FindNextFile</I>.</P>
<P>The function <I>CeFindFirstDatabase</I> takes the form:</P>
<!-- CODE SNIP //-->
<PRE>
CeFindFirstDatabase(dwDbaseType);
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>dwDbaseType</I> parameter is the database type identifier of interest. This can be any application-defined database type. Note, however, that if you specify zero for <I>dwDbaseType</I>, an enumeration context for <I>all</I> databases in the object store is returned. If successful, <I>CeFindFirstDatabase</I> returns an enumeration context for this database type. If the function fails, it returns INVALID_HANDLE_VALUE.</P>
<P><I>CeFindNextDatabase</I> looks like this:</P>
<!-- CODE SNIP //-->
<PRE>
CeFindNextDatabase(hEnum);
</PRE>
<!-- END CODE SNIP //-->
<P><I>hEnum</I> is the enumeration context returned by the <I>CeFindFirstDatabase</I> call. This function returns the object identifier of the next enumerated database, or zero if the function fails.</P>
<P>Database enumeration can be used to perform a number of operations in your applications. For example, if you wanted to delete all databases of a particular type, <I>CeFindNextDatabase</I> could be used to get the object identifier of each database of that type, and <I>CeDeleteDatabase</I> would then delete each of the databases.</P>
<P>At other times, you may wish to determine a particular set of attributes for each database of some type. An example might be getting the name of every database in the object store. Such features would be implemented using the <I>CeOidGetInfo</I> function. As an example, let’s take a look at how you might get the total amount of memory in bytes in use by databases on a Windows CE device.</P>
<!-- CODE //-->
<PRE>
CEOID oidTemp;
CEOIDINFO oidInfo;
HANDLE hEnum;
DWORD dwBytes;
TCHAR pszText[129];
hEnum = CeFindFirstDatabase(0);
if (INVALID_HANDLE_VALUE!=hEnum)
{
dwBytes = 0;
while (oidTemp = CeFindNextDatabase(hEnum))
{
CeOidGetInfo(oidTemp, &oidInfo);
dwBytes += oidInfo.infDatabase.dwSize;
}
CloseHandle(hEnum);
wsprintf(pszText, TEXT("%ld bytes in use"), dwBytes);
MessageBox(NULL, pszText,
TEXT("Database Memory Consumption"), MB_OK);
}
else
{
MessageBox(NULL, TEXT("Invalid Enumeration Context"),
TEXT("Enumeration Error"), MB_OK|MB_ICONEXCLAMATION);
}
</PRE>
<!-- END CODE //-->
<P>This sample opens an enumeration context into all of the databases in the object store of the device on which the code is executed by calling <I>CeFindFirstDatabase</I> with <I>dwDbaseType</I> argument of zero. <I>CeOidGetInfo</I> is then called for each database. A running byte count is updated using the size of each enumerated database. The database size is found in the <I>dwSize</I> member of the CEDBASEINFO structure returned as part of <I>oidInfo</I>. The total byte count is then displayed in a message dialog box.</P>
<H3><A NAME="Heading11"></A><FONT COLOR="#000077">Database Notifications</FONT></H3>
<P>The last Windows CE database topic that needs to be covered is database notifications. In all of our examples we have passed NULL to the <I>hwndNotify</I> argument of <I>CeOpenDatabase</I>. However, this parameter can be used to specify a window that receives notifications whenever another thread of execution modifies the particular database before the thread that opened the database closes it. If the <I>hwndNotify</I> parameter is NULL, the thread opening the database is indicating it is not interested in receiving any such notifications.</P>
<P>There are three notifications that can be sent to the <I>hwndNotify</I> window. Although called notifications, they are actually Windows CE messages that are posted to the <I>hwndNotify</I> window. To respond to them, then, your application needs to include handlers for the ones you are interested in <I>hwndNotify</I>’s window procedure. The descriptions of the three notifications (messages) are given in Table 7.4.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 7.4</B> Database Notifications
<TR>
<TH WIDTH="30%" ALIGN="LEFT">NOTIFICATION NAME
<TH WIDTH="20%" ALIGN="LEFT">MEANING
<TH WIDTH="20%" ALIGN="LEFT">WPARAM
<TH WIDTH="30%" ALIGN="LEFT">LPARAM
<TR>
<TD VALIGN="TOP">DB_CEOID_CHANGED
<TD VALIGN="TOP">Object modified
<TD VALIGN="TOP">CEOID of
<TD>CEOID of modified object modified object’s parent
<TR>
<TD>DB_CEOID_CREATED
<TD>Object created
<TD>CEOID of new object
<TD>CEOID of new object’s parent
<TR>
<TD VALIGN="TOP">DB_CEOID_RECORD_DELETED
<TD VALIGN="TOP">Record deleted
<TD VALIGN="TOP">CEOID of deleted
<TD>CEOID of Object deleted object’s parent
</TABLE>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="209-211.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="214-216.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 + -