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

📄 263-266.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:


<!-- 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=263-266//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="259-263.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="266-269.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B><I>The Memory Device Context</I></B></FONT></P>
<P>A memory device context is similar to a window device context. The difference is that a memory device context represents a virtual display surface. It is a display surface in memory only. Other than this important distinction, a memory device context is like any other device context.
</P>
<P>A memory device context becomes really useful when it has a bitmap selected into it. Then any graphics function call that operates on the memory device context has the effect of producing the result of the function call on the selected bitmap.</P>
<P>Thus, if an application selects a bitmap into a memory device context and then draws a rectangle on that device context, the bitmap will contain that rectangle.</P>
<P>A memory device context is created with the function <I>CreateCompatibleDC</I>:</P>
<!-- CODE SNIP //-->
<PRE>
  CreateCompatibleDC(hdc);
</PRE>
<!-- END CODE SNIP //-->
<P>This function returns a memory device context with the same attributes as that specified by the parameter <I>hdc</I>.</P>
<P><FONT SIZE="+1"><B><I>Creating the Bitmap</I></B></FONT></P>
<P>The second ingredient we need in order to produce an offscreen bitmap is the bitmap object itself. For this purpose an application calls <I>CreateCompatibleBitmap</I>:</P>
<!-- CODE SNIP //-->
<PRE>
  CreateCompatibleBitmap(hdc, nWidth, nHeight);
</PRE>
<!-- END CODE SNIP //-->
<P>This function returns a handle to a BITMAP object (HBITMAP) <I>nWidth</I> pixels wide and <I>nHeight</I> pixels tall. The number of bits per pixel and the number of color planes of the bitmap are the same as those of the device context specified in <I>hdc</I>. A bitmap created in this way is called an offscreen bitmap.</P>
<P>Once a bitmap has been created in this way, it can be selected into a memory device context with a call to <I>SelectObject</I>. Any subsequent graphics operations involving that memory device context are rendered on the offscreen bitmap.</P>
<P>In the case of the KIOSK.EXE application, the offscreen bitmap containing the banner text is produced with the following code. <I>hdc</I> is the main application window device context. <I>nRight</I> and <I>nBottom</I> are the width and height of the main application window.</P>
<!-- CODE //-->
<PRE>
  #define BK_COLOR (RGB(0,0,0)) //Black text background
  #define TEXT_COLOR (RGB(255,255,0)) //Yellow text
  HDC hdcMem;
  HBITMAP hBmp;
  RECT rc;
  TCHAR* pszBanner[] = TEXT(&#147;Tap Anywhere To Begin&#148;);
  hdcMem = CreateCompatibleDC(hdc);
  hBmp = CreateCompatibleBitmap(
    hdc, nRight, nBottom);
  SelectObject(hdcMem, hBmp);
  SetBkColor(hdcMem, BK_COLOR);
  SetTextColor(hdcMem, TEXT_COLOR);
  DrawText(hdcMem, pszBanner, -1, &#38;rc, DT_LEFT);
</PRE>
<!-- END CODE //-->
<P>The last three statements in the example above operate on the memory device context <I>hdcMem</I>. The operations they represent are therefore rendered on the offscreen bitmap currently selected into that device context.</P>
<P><FONT SIZE="+1"><B><I>Making the Text Scroll</I></B></FONT></P>
<P>At this point, the application has the complete offscreen bitmap for displaying the kiosk banner text. Making this text scroll is now very simple.
</P>
<P>The main application window simply draws the offscreen bitmap whenever the window gets painted. The scrolling effect is achieved by updating the location at which the bitmap is drawn. This position is updated in response to the IDT_SCROLL timer firing.</P>
<P>Inside the window procedure for the main window, we find this code:</P>
<!-- CODE //-->
<PRE>
  case WM_TIMER:
    if (IDT_SCROLL==wParam)
    &#123;
     nScrollX &#43;= 50;
    if (nScrollX &gt; nRight)
    &#123;
     nScrollX = -nStringWidth;
    &#125;
    InvalidateRect(hwnd, NULL, TRUE);
    &#125;
    return (0);
</PRE>
<!-- END CODE //-->
<P><I>nStringWidth</I> is the width of the banner text string in pixels. It is calculated at the beginning of the application with a <I>DrawText</I> call that uses DT_CALCRECT as a text drawing option.</P>
<P><I>nScrollX</I> is an integer initialized to zero in <I>WinMain</I>. It represents the current x position in pixels of the offscreen bitmap. On every IDT_SCROLL timer tick, this value gets incremented by 50 pixels.</P>
<P>Once <I>nScrollX</I> exceeds <I>nRight</I>, the right edge of the main window, <I>nScrollX</I> is set to the value -<I>nStringWidth</I>. This effectively moves the offscreen bitmap off the left edge of the main window.</P>
<P>The <I>InvalidateRect</I> call tells Windows CE that the entire client area of the main application window must be redrawn. So, the entire window is redrawn after every IDT_SCROLL timer interval.</P>
<P>The main window is drawn with the WM_PAINT handler code:</P>
<!-- CODE SNIP //-->
<PRE>
  case WM_PAINT:
    PAINTSTRUCT ps;
    hdc = BeginPaint(hwnd, &#38;ps);
    BitBlt(hdc, nScrollX, 0, nRight, nBottom,
     hdcMem, 0,0, SRCCOPY);
    EndPaint(hwnd, &#38;ps);
    return (0);
</PRE>
<!-- END CODE SNIP //-->

<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Why Not Just Use ScrollWindowEx?</B></FONT>
<P>Experienced Windows programmers might question my method of implementing scrolling text with an offscreen bitmap. Why not just draw the text once using <I>DrawText</I>, and then call <I>ScrollWindowEx</I> in response to the WM_TIMER message?</P>
<P>In addition to giving me an excuse to introduce the offscreen bitmap concept to programmers who may not be familiar with it, my method also makes it easier to produce the scrolling text effect.</P>
<P><I>ScrollWindowEx</I> only scrolls pixels that appear on the window specified by the <I>hWnd</I> parameter of <I>ScrollWindowEx</I>. After the text scrolls off the right side of the main window, it re-enters the screen from the left. Producing this effect without a bitmap, which has a fixed set of bits, would require clever <I>DrawText</I> calls to draw incomplete portions of the text to make it appear to scroll back on the screen.</P>
</TABLE>

<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="259-263.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="266-269.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 + -