📄 317-320.html
字号:
<!-- 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=317-320//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="313-317.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="320-322.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The main application window was shown in Figure 12.1. When the application first starts, there is no HTML displayed, however. Users can display files by opening them with the Open option of the File menu. Choosing this option presents the user with a standard File Open dialog shown in Figure 12.3. Using this interface, the user can search the file system for a particular HTML file. Selecting the file and pressing the OK button causes the application to display the contents of the selected file.
</P>
<P><A NAME="Fig3"></A><A HREF="javascript:displayWindow('images/12-03.jpg',480,240 )"><IMG SRC="images/12-03t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/12-03.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 12.3</B></FONT></A> The File Open dialog for selecting HTML files.</P>
<H3><A NAME="Heading4"></A><FONT COLOR="#000077">Preparing to Use the HTML Viewer Control</FONT></H3>
<P>As mentioned earlier, an application must initialize the HTMLVIEW.DLL module before instances of the HTML viewer control can be created and used. Applications can link with HTMLVIEW.DLL dynamically, or they can link with HTMLVIEW.LIB to avoid loading the DLL at run-time.
</P>
<P>To make the application a little less complicated, HTML.EXE links with the import library. It can therefore call <I>InitHTMLControl</I> directly. The only thing that must be done that we have not yet mentioned is that the application must include the file HTMLCTRL.H. This is the header file that defines all of the messages and notifications which the HTML viewer control can send, as well as the function <I>InitHTMLControl</I>.</P>
<P><I>InitHTMLControl</I> must be called in order to register the window class that defines the HTML viewer control. This step is analogous to calling <I>InitCommonControls</I> before using COMMCTRL.DLL.</P>
<P>HTML.EXE calls <I>InitHTMLControl</I> in <I>WinMain</I>:</P>
<!-- CODE //-->
<PRE>
#include <htmlctrl.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
/* Other application code */
...
InitHTMLControl(hInstance);
...
}
</PRE>
<!-- END CODE //-->
<P><I>InitHTMLControl</I> takes only one argument: the HINSTANCE of the application that is using the control. It returns TRUE if the window class is registered properly. Otherwise it returns FALSE.</P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">Creating HTML Viewer Controls</FONT></H3>
<P>You are now ready to create instances of the HTML viewer control. This step is done with <I>CreateWindow</I> or <I>CreateWindowEx</I>, just as when creating any other Windows CE control. The only thing left to know is the name of the window class to use.</P>
<P>The HTML viewer control window class is called DISPLAYCLASS. That’s an obvious one, isn’t it? To create a control with a control identifier defined as IDC_HTML and whose parent is <I>hwndParent</I>, an application would do this:</P>
<!-- CODE SNIP //-->
<PRE>
HWND hwndHTML;
hwndHTML = CreateWindow(
TEXT("DISPLAYCLASS"), NULL,
WS_CHILD|WS_VISIBLE|WS_BORDER,
0,0,100,100, //i.e., some dimensions
hwndParent, (HMENU)IDC_HTML,
hInstance, NULL);
</PRE>
<!-- END CODE SNIP //-->
<P>The control, referred to by <I>hwndHTML</I>, is now ready to display HTML data.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B><B>HTML V<SMALL>IEWER</SMALL> C<SMALL>ONTROL</SMALL> S<SMALL>TYLES</SMALL></B>
<P><B>Unlike most of the other Windows CE controls, the HTML viewer control defines no control-specific styles or extended styles to allow programmers to customize the control’s appearance or behavior.</B><HR></FONT>
</BLOCKQUOTE>
</P>
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">Displaying HTML Formatted Text</FONT></H3>
<P>As an HTML viewer, the HTML viewer control must provide a way for applications to give it HTML text to display.
</P>
<P>Text is inserted into the control by sending either the message DTM_ADDTEXT or DTM_ADDTEXTW. DTM_ADDTEXT is for adding non-Unicode text. DTM_ADDTEXTW is the Unicode version.</P>
<P>HTML.EXE uses DTM_ADDTEXT because it assumes that the files it reads are saved as ANSI text, not Unicode.</P>
<P>As the name of these two messages implies, they add text to the specified control. So if there is already text in an HTML viewer control before an application sends one of these messages, the text is added to the bottom of the control’s client area. The message does not cause the control to clear its contents before the new text is displayed.</P>
<P>In order to display text by itself, you must first remove the current contents of the control. The easiest way to do this is to send a WM_SETTEXT message to the control with a NULL text string:</P>
<!-- CODE SNIP //-->
<PRE>
SendMessage(hwndHTML, WM_SETTEXT, 0, NULL);
</PRE>
<!-- END CODE SNIP //-->
<P>Closely related to these ADDTEXT messages is the message DTM_ENDOFSOURCE. An application sends this message to an HTML viewer control to tell it that the application is done sending text. Both parameters to this message, <I>wParam</I> and <I>lParam</I>, are zero.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B><B>D<SMALL>O</SMALL> Y<SMALL>OU</SMALL> R<SMALL>EALLY</SMALL> N<SMALL>EED</SMALL> DTM_ENDOFSOURCE?</B>
<P><B>It appears that not sending DTM_ENDOFSOURCE has no negative side effects.</B><HR></FONT>
</BLOCKQUOTE>
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="313-317.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="320-322.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 + -