📄 266-269.html
字号:
<!-- 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=9//-->
<!--PAGES=266-269//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="263-266.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="269-272.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The <I>BitBlt</I> call redraws the offscreen bitmap containing the text at the new <I>nScrollX</I> x location.</P>
<P><FONT SIZE="+1"><B>Implementing the Options Window</B></FONT></P>
<P>The window that appears when a user taps the kiosk application’s main window is called the options window. It is the window that the user interacts with to make various banking choices (Figure 9.4).
</P>
<P><A NAME="Fig4"></A><A HREF="javascript:displayWindow('images/09-04.jpg',480,240 )"><IMG SRC="images/09-04t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-04.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 9.4</B></FONT></A> The Kiosk application options window.</P>
<P>The options window is another example of a Windows CE user interface designed to look very little like traditional windows. The options window allows users to check their bank account balance, make a deposit, or withdraw cash. Of course none of this banking functionality is actually implemented by KIOSK.EXE. The point of the options window and the entire kiosk sample application is to give you insight into the Windows CE options available for implementing non-standard user interfaces.
</P>
<P>The options window consists of three owner draw buttons, a custom window border, and some descriptive text. Like the main window, it has no title bar or window caption.</P>
<P>The options window class is defined and registered as follows:</P>
<!-- CODE //-->
<PRE>
TCHAR pszEntryClass[] = TEXT("ENTRYWINDOW");
WNDCLASS wndClassOptions;
wndClassOptions.style = 0;
wndClassOptions.lpfnWndProc = OptionsWndProc;
wndClassOptions.cbClsExtra = 0;
wndClassOptions.cbWndExtra = 0;
wndClassOptions.hInstance = hInstance;
wndClassOptions.hIcon = NULL;
wndClassOptions.hCursor = NULL;
wndClassOptions.hbrBackground=
(HBRUSH)GetStockObject(WHITE_BRUSH);
wndClassOptions.lpszMenuName = NULL;
wndClassOptions.lpszClassName= pszEntryClass;
RegisterClass(&wndClassOptions);
</PRE>
<!-- END CODE //-->
<P><I>OptionsWndProc</I> is the window procedure for the options window.</P>
<P>Also notice the WHITE_BRUSH background instead of the BLACK_BRUSH background defined for the main window class.</P>
<P>When a user taps the main application screen, an instance of this window class is created. Since the options window appears as a result of tapping the main application window, the options window <I>CreateWindow</I> call must appear in the WM_LBUTTONDOWN message handler of the main window’s window procedure as shown below. Only the part of the window procedure relevant to options window creation is included here.</P>
<!-- CODE //-->
<PRE>
HWND hwndOptions;
int nOptionsWidth, nOptionsHeight;
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
/* Other message handlers here… */
case WM_LBUTTONDOWN:
nOptionsWidth = (nRight-50);
nOptionsHeight= (nBottom-50);
KillTimer(hwndMain, IDT_SCROLL);
hwndOptions = CreateWindow(pszEntryClass,
NULL, WS_VISIBLE,
20, 20, nOptionsWidth, nOptionsHeight,
hwnd, NULL, ghInst, NULL);
return (0);
/* Other message handlers… */
default:
return (DefWindowProc(hwnd, message, wParam, lParam));
} //End of switch(message) statement
}
</PRE>
<!-- END CODE //-->
<P><I>nRight</I> and <I>nBottom</I> are the horizontal and vertical dimensions of the main window’s bounding rectangle. <I>ghInst</I> is the globally defined application instance.</P>
<P>The first thing to notice in this code is the <I>KillTimer</I> call. When the options window is displayed, the text on the main application window stops scrolling. This is done by simply turning the scrolling timer IDT_SCROLL off.</P>
<P>The <I>CreateWindow</I> call makes an instance of the options window class that contains only the WS_VISIBLE style. Thus the window does not include the standard Windows CE border or caption bar. The window does appear to have a border, though. This is rendered by the application in response to the WM_ERASEBKGND messages that are sent to the options window.</P>
<P><FONT SIZE="+1"><B><I>Drawing the Options Window Border</I></B></FONT></P>
<P>The WM_ERASEBKGND message is similar to its more well known cousin, WM_PAINT. A WM_PAINT message is sent to a window whenever part or all of the window’s client area needs to be repainted. Similarly, WM_ERASEBKGND is sent when part or all of a window’s client area needs to be erased.
</P>
<P>For example, we’ve probably all seen applications that have windows with interesting bitmaps as their background. These backgrounds are drawn in response to WM_ERASEBKGND messages (Table 9.3). Including the WM_ERASEBKGND message in the operating system allows applications to break the process of drawing windows into two steps. The WM_ERASEBKGND step can be used to draw the fixed parts of a window’s client area display such as custom backgrounds. WM_PAINT is then used to paint the parts of the display that change, such as the text that appears on a page in a word processing application.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 9.3</B> The WM_ERASEBKGND Message Parameters
<TR>
<TH WIDTH="30%" ALIGN="LEFT">PARAMETER
<TH WIDTH="70%" ALIGN="LEFT">MEANING
<TR>
<TD>(HDC)wParam
<TD>Device context of the window whose background is to be erased.
<TR>
<TD>lParam
<TD>Not used.
</TABLE>
<P>The value returned by a window procedure that handles the WM_ERASEBKGND is very important. Returning the wrong value can lead to very subtle bugs in an application which appear as window backgrounds being drawn incorrectly. An application should return a non-zero value if it handles the WM_ERASEBKGND message. This tells Windows CE not to perform the default WM_ERASEBKGND processing. Returning zero tells Windows CE that the default processing should be performed.
</P>
<P>This is how the <I>hbrBackground</I> member of the window class definition gets used by Windows CE. If an application leaves the processing of WM_ERASEBKGND messages to Windows CE (either by returning zero in response to the message or by calling <I>DefWindowProc</I> for WM_ERASEBKGND messages), Windows CE erases the window background itself. It does so by filling the window’s client area with the brush specified in the <I>hbrBackground</I> member of the window class definition for the particular window. This is how, for example, the background of the kiosk application’s main window is painted black.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="263-266.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="269-272.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 + -