📄 207-209.html
字号:
<!--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=207-209//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="204-207.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="209-211.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Managing Records More Cleanly</B></FONT></P>
<P>The preceding examples of how to write and read database records leave something to be desired. In both cases, you might have been left with the impression that Windows CE database applications only work with record data in raw binary form. While it is true that the <I>CeReadRecordProps</I> always return an LPBYTE array of data, and <I>CeWriteRecordProps</I> always writes record information as a collection of somewhat cumbersome CEPROPVAL structures, it is possible to write your applications in such a way that the rest of your application can treat database records in a more natural form. Specifically, your application can define a structure that is used to represent the more abstract notion of records in your database.</P>
<P>For example, in the case of the phone list application, it seems natural to represent an entry in the phone list with a structure like this:</P>
<!-- CODE SNIP //-->
<PRE>
typedef struct _PhoneRecord
{
TCHAR lpszLastName[MAX_NAME_LENGTH];
TCHAR lpszFirstName[MAX_NAME_LENGTH];
TCHAR lpszPhoneNumber[MAX_NAME_LENGTH];*
int nDept;
}PHONERECORD, *LPPHONERECORD;
</PRE>
<!-- END CODE SNIP //-->
<P>No CEPROPVALSs, CEOIDs, or other abstract database concepts here. A phone record is just a collection of values of C data types that we know and love. When users enter new records through the application’s user interface, the application code can assign the values entered into the appropriate fields of an instance of this clear-cut data type. The mechanics of turning the elements of this structure into the form required in order to write the record to the database can be left to the inner workings of one simple <I>ReadRecord</I> function:</P>
<!-- CODE //-->
<PRE>
EOID ReadRecord(LPPHONERECORD lppr)
{
WORD cProps = 0;
LPBYTE pBuf=NULL;*
DWORD cbByte = 0;*
PCEPROPVAL pVals;*
CEOID oid;
int i;
oid = CeReadRecordProps(hDBase, CEDB_ALLOWREALLOC,
&cProps, NULL,&pBuf, &cbByte);
pVals = (PCEPROPVAL)pBuf;
for (i=0; i<cProps; i++)
{
switch(HIWORD(pVals[i].propid))
{
case PL_LASTNAME_INDEX:
lstrcpy(lppr->lpszLastName,
pVals[i].val.lpwstr);
break;
case PL_FIRSTNAME_INDEX:
lstrcpy(lppr->lpszFirstName,
pVals[i].val.lpwstr);
break;
case PL_PHONENUMBER_INDEX:
lstrcpy(lppr->lpszPhoneNumber,
pVals[i].val.lpwstr);
break;
case PL_DEPT_INDEX:
lppr->nDept = pVals[i].val.iVal;
break;
default:
break;
} //End of switch statement
} //End of for (i=0; i<cProps; i++) loop
LocalFree(pBuf);
return (oid);
}
</PRE>
<!-- END CODE //-->
<P>Writing phone list records can be abstracted in much the same way with <I>WriteRecord</I>:</P>
<!-- CODE //-->
<PRE>
CEOID WriteRecord(LPPHONERECORD lppr)
{
CEPROPVAL cePropVal[PROPERTY_COUNT];
CEOID ceoid;
HANDLE hDBase;
WORD wCurrent = 0;
hDBase = OpenPhoneDatabase(szDBaseName, 0,
CEDB_AUTOINCREMENT, NULL, &ceoidDBase);
memset(&cePropVal, 0, sizeof(CEPROPVAL)*PROPERTY_COUNT);
cePropVal[wCurrent].propid = PL_LASTNAME;
cePropVal[wCurrent++].val.lpwstr = lppr->lpszLastName;
cePropVal[wCurrent].propid = PL_FIRSTNAME;
cePropVal[wCurrent++].val.lpwstr = lppr->lpszFirstName;
cePropVal[wCurrent].propid = PL_PHONENUMBER;
cePropVal[wCurrent++].val.lpwstr = lppr->lpszPhoneNumber;
cePropVal[wCurrent].propid = PL_DEPT;
cePropVal[wCurrent++].val.iVal = lppr->nDept;
ceoid = CeWriteRecordProps(hDBase, 0, wCurrent,
cePropVal);
CloseHandle(hDBase); /Close the database
return (ceoid);
}
</PRE>
<!-- END CODE //-->
<P>The rest of the application can now treat phone list data in the way that you would normally model the concept of a record, as a standard C structure.
</P>
<H3><A NAME="Heading9"></A><FONT COLOR="#000077">Searching for Records</FONT></H3>
<P>The function used for searching for records is <I>CeSeekDatabase</I>:</P>
<!-- CODE SNIP //-->
<PRE>
CeSeekDatabase(hDatabase, dwSeekType, dwValue, lpdwIndex);
</PRE>
<!-- END CODE SNIP //-->
<P><I>hDatabase</I> is a handle to the open database. <I>dwSeekType</I> is a DWORD that indicates to the function what kind of database search to perform. It also defines where the database current record pointer is positioned at the end of the seek operation. <I>lpdwIndex</I>, the last parameter, is a pointer to a DWORD that <I>CeSeekDatabase</I> uses to return the 0-based index of the record that was found by the seek operation. <I>dwValue</I> has different meanings depending on the value of <I>dwSeekType</I>.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="204-207.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="209-211.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 + -