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

📄 259-263.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=9//-->
<!--PAGES=259-263//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="257-259.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="263-266.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Adding the Scrolling Text</B></FONT></P>
<P>The scrolling banner text in the main application window is implemented using a bitmap and a Windows CE <I>timer</I>.</P>
<P><FONT SIZE="+1"><B><I>Windows CE Timers</I></B></FONT></P>
<P>A timer is a device that applications can use to have Windows CE notify them that a specified interval of time has elapsed. In our case, the timer fires every 0.5 seconds. In response to this timer, the main window produces the effect of scrolling the text by repainting the bitmap in a new position.
</P>
<P>Timers are used extensively in a wide variety of Windows CE applications. For example, calendar applications use timers to trigger the alarms that users set to remind them of scheduled appointments.</P>
<P>Each timer that an application creates is associated with a particular window. Windows CE notifies a window that a timer associated with it has elapsed by sending a WM_TIMER message to that window&#146;s window procedure. Alternatively, an application-defined callback function can be specified for each timer. In this case, the callback function assigned to the timer is called.</P>
<P>To create the timer, KIOSK.EXE calls the <I>SetTimer</I> Windows CE function:</P>
<!-- CODE SNIP //-->
<PRE>
  SetTimer(hwnd, uIDEvent, uElapse, lpTimerFunc);
</PRE>
<!-- END CODE SNIP //-->
<P><I>SetTimer</I> returns the identifier of the new timer (i.e., <I>uIDEvent</I>) if the function succeeds. Otherwise the return value is zero.</P>
<P><I>hwnd</I> is the window that owns the timer. Since a window can own more than one timer, Windows CE needs a way to distinguish between timers. Callers therefore specify the <I>uIDEvent</I> parameter. <I>uIDEvent</I> is a UINT identifying the timer. <I>uElapse</I> defines the <I>timer interval</I>, the number of milliseconds that elapse between WM_TIMER messages.</P>
<P><I>lpTimerFunc</I> is a pointer to a timer callback function. This is the function that gets called by Windows CE whenever the timer interval identified by <I>uIDEvent</I> elapses. A timer callback function has the following signature:</P>
<!-- CODE SNIP //-->
<PRE>
  VOID CALLBACK TimerProc(hwnd, uMsg, idEvent, dwTime);
</PRE>
<!-- END CODE SNIP //-->
<P><I>hwnd</I> and <I>idEvent</I> identify the window that owns the timer and the timer identifier, respectively. <I>idEvent</I> is the same as the <I>uIDEvent</I> value that is in the <I>SetTimer</I> call.</P>
<P>The <I>uMsg</I> parameter is always WM_TIMER for a timer callback. Given that a timer callback is always called because a timer interval has elapsed, it is anyone&#146;s guess why this parameter was added to the function definition.</P>
<P><I>dwTime</I> gives the number of milliseconds since Windows CE was launched on the device hosting the application.</P>
<P>If you are like me, you might prefer to set <I>lpTimerFunc</I> to NULL. In this case, Windows CE sends a WM_TIMER message to the window that owns a timer whose <I>uElapse</I> interval has elapsed (Table 9.2). All of the information that you would get from a timer callback is available to any window procedure that handles this message. Perhaps this is why most people don&#146;t bother using timer callbacks.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 9.2</B> The WM_TIMER Message
<TR>
<TH WIDTH="40%" ALIGN="LEFT">PARAMETER
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD VALIGN="TOP">(UINT)wParam
<TD>Identifier of the timer whose interval elapsed, causing the WM_TIMER message to be sent.
<TR>
<TD>(TIMERPROC*)lParam
<TD>Pointer to the timer callback function.
</TABLE>
<P>If the <I>lpTimerFunc</I> parameter of <I>SetTimer</I> is NULL, <I>lParam</I> will be NULL for the corresponding WM_TIMER messages.</P>
<P>KIOSK.EXE creates one timer identified as IDT_SCROLL and assigns it to the main application window. The IDT_SCROLL timer fires every 0.5 seconds.</P>
<P>The main window responds to IDT_TIMER by scrolling the banner text. The WM_TIMER handler of the main window&#146;s window procedure looks like this:</P>
<!-- CODE SNIP //-->
<PRE>
  case WM_TIMER:
    if (IDT_SCROLL==wParam)
    &#123;
     //Perform scrolling
    &#125;
    return (0);
</PRE>
<!-- END CODE SNIP //-->
<P>A WM_TIMER handler typically checks the identity of the timer whose interval has elapsed and performs whatever action that timer was meant to trigger.
</P>
<P>An application can destroy a timer by calling <I>KillTimer</I>:</P>
<!-- CODE SNIP //-->
<PRE>
  KillTimer(hwnd, uIDEvent);
</PRE>
<!-- END CODE SNIP //-->
<P><I>hwnd</I> identifies the window that owns the timer to be destroyed, and <I>uIDEvent</I> is the timer identifier. If the timer specified by <I>uIDEvent</I> is successfully destroyed, <I>KillTimer</I> returns TRUE. Otherwise it returns FALSE.</P>
<P><FONT SIZE="+1"><B><I>Creating the Text: Offscreen Bitmaps</I></B></FONT></P>
<P>The text that scrolls across the kiosk application&#146;s main window is implemented as a bitmap. But you will search in vain if you try to find a bitmap resource somewhere in the project files on the companion CD that has the text &#147;Tap Anywhere To Begin&#148; in it.
</P>
<P>This is because the bitmap that is used to draw the scrolling text is created programmatically. It is done using a common Windows CE graphics programming technique known as drawing an <I>offscreen bitmap</I>.</P>
<P>An offscreen bitmap is a bitmap like any other. The only difference, as the name implies, is that the bits that constitute the bitmap reside in some portion of program memory that is not owned by the display device. The basic idea is that an application generates the bitmap off screen, and then renders it in some device context when needed.</P>
<P>Note that the actual string &#147;Tap Anywhere To Begin&#148; is stored in a Unicode string variable called <I>pszText</I>, defined in the project file KIOSK.H. The offscreen bitmap is generated using this string. So when we say that the text scrolls across the screen, what we really mean is that the offscreen bitmap representing the string is being scrolled.</P>
<P>There are two primary ingredients required to create an offscreen bitmap. The first is a <I>memory device context</I>. The second is the bitmap itself.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>TIP:&nbsp;&nbsp;</B><B>S<SMALL>TORING</SMALL> T<SMALL>HE</SMALL> B<SMALL>ANNER</SMALL> T<SMALL>EXT</SMALL> I<SMALL>N</SMALL> T<SMALL>HE</SMALL> R<SMALL>EGISTRY</SMALL></B>
<P><B>Chapter 8 discussed the Windows CE registry as one form of persistent storage. In a complete commercial kiosk application, the scrolling banner text string would most likely be stored in the registry. This would allow the banner text to be changed without requiring the application to be recompiled.</B><HR></FONT>
</BLOCKQUOTE>
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="257-259.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="263-266.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 + -