?? 320-322.html
字號:
</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=""> <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=12//-->
<!--PAGES=320-322//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="317-320.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="322-325.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>An Example</B></FONT></P>
<P>The sample application HTML.EXE allows users to pick the HTML file to display using a File Open dialog. Once a file is specified, the application must read the HTML text from the file and send it to the HTML viewer control using the DTM_ADDTEXT message.
</P>
<P>The function that HTML.EXE uses to load an HTML file is called <I>LinkToFile</I>. (This name will make more sense a bit later when we see that the application uses the same function for following hyperlinks.)</P>
<!-- CODE //-->
<PRE>
void LinkToFile(TCHAR* pszFilename)
{
DWORD dwSize, dwBytes;
LPSTR lpszBuf;
WIN32_FIND_DATA fd;
CEOIDINFO oidInfo;
//Clear the control
SendMessage(hwndHTML, WM_SETTEXT, 0, NULL);
hFile = FindFirstFile(pszFilename, &fd);
if (INVALID_HANDLE_VALUE!=hFile)
{
CeOidGetInfo(fd.dwOID, &oidInfo);
dwSize = oidInfo.infFile.dwLength+1;
FindClose(hFile);
}
hFile = CreateFile(pszFilename,
GENERIC_READ, 0,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
lpszBuf = (LPSTR)LocalAlloc(LPTR, dwSize+1);
lpszBuf[dwSize] = 0; //Add NULL terminator
ReadFile(hFile, lpszBuf, dwSize, &dwBytes, NULL);
SendMessage(hwndHTML, DTM_ADDTEXT,
(WPARAM)FALSE, (LPARAM)lpszBuf);
SendMessage(hwndHTML, DTM_ENDOFSOURCE, 0, 0);
CloseHandle(hFile);
}
</PRE>
<!-- END CODE //-->
<P><I>hwndHTML</I> is the window handle of the HTML viewer control. It is defined as a global variable so that the entire application can reference it. <I>LinkToFile</I> looks formidable, but it is actually quite straightforward.</P>
<P>First it searches the file system for the file specified by the parameter <I>pszFilename</I>. The application already knows the name of the file to display because the user selected a file from the File Open dialog. But the application calls <I>FindFirstFile</I> in order to get the object identifier of the selected file. It can then get the size of the file with the <I>CeOidGetInfo</I> call, which it needs to allocate space for the file contents. The function then opens the file with the appropriate call to <I>CreateFile</I>.</P>
<P>Next, <I>LinkToFile</I> allocates enough space in the buffer <I>lpszBuf</I> to hold the contents of the entire file by calling <I>LocalAlloc</I>. It knows the size it needs to allocate because previously the function determined the byte size of the file. Once the <I>lpszBuf</I> is allocated, <I>ReadFile</I> fills the buffer with the contents of the file <I>pszFilename</I>.</P>
<P>Finally, <I>LinkToFile</I> sends a DTM_ADDTEXT message to display the HTML text it just read in the HTML viewer control:</P>
<!-- CODE SNIP //-->
<PRE>
SendMessage(hwndHTML, DTM_ADDTEXT,
(WPARAM)FALSE, (LPARAM)lpszBuf);
</PRE>
<!-- END CODE SNIP //-->
<P>As noted in Table 12.1, the FALSE <I>wParam</I> parameter tells the control to treat the contents of <I>lpszBuf</I> as HTML formatted text.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 12.1</B> The DTM_ADDTEXT/DTM_ADDTEXTW Messages
<TH WIDTH="40%" ALIGN="LEFT">PARAMETER
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD VALIGN="TOP">(BOOL)wParam
<TD>Indicates the type of text to add. If TRUE, the control treats the text as plain text. If FALSE, the control treats the text as HTML formatted text.
<TR>
<TD VALIGN="TOP">(LPSTR)lParam or (LPWSTR)lParam
<TD>Pointer to the string to be added. String is ANSI for DTM_ADDTEXT, Unicode for DTM_ADDTEXTW.
</TABLE>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Handling Hyperlinks</FONT></H3>
<P>The Windows CE HTML viewer control provides some built-in support for hyperlinks in HTML formatted text. The control knows how to recognize anchor tags. The text corresponding to an anchor is automatically formatted when the HTML viewer control displays the text. Specifically, the text color is changed to blue and the text is underlined.
</P>
<P>The HTML viewer control also notifies its parent window whenever a user taps on such a link on the display screen. All of the logic for determining where the stylus taps the screen and decides if that point corresponds to a link is implemented in the viewer control’s window procedure.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="317-320.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="322-325.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 + -