📄 269-272.html
字号:
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=269-272//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="266-269.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="272-274.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>You can see how telling Windows CE that you erased your window background when you really didn’t can cause problems. Incorrectly returning a non-zero value in response to WM_ERASEBKGND can prevent the proper background from being painted.
</P>
<P>In the case of the options window in the kiosk application, WM_ERASEBKGND is used to draw the window border. The relevant portion of the <I>OptionsWndProc</I> window procedure is shown below:</P>
<!-- CODE //-->
<PRE>
LRESULT CALLBACK OptionsWndProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
HDC hdc;
UINT nID;
RECT rc;
switch(message)
{
//Other message handlers */
//…
case WM_ERASEBKGND:
HBRUSH hBrushOld;
hdc = (HDC)wParam;
GetClientRect(hwnd, &rc);
hBrushOld = (HBRUSH)SelectObject(hdc,
GetStockObject(WHITE_BRUSH));
Rectangle(hdc, rc.left, rc.top,
rc.right, rc.bottom);
InflateRect(&rc, -3, -3);
Rectangle(hdc, rc.left, rc.top,
rc.right, rc.bottom);
SelectObject(hdc, hBrushOld);
return (TRUE);
default:
return (DefWindowProc(hwnd, message, wParam, lParam));
} //End of switch(message) statement
}
</PRE>
<!-- END CODE //-->
<P>The WM_ERASEBKGND handler first extracts the HDC of the options window from the <I>wParam</I> parameter of the window procedure. Next it gets the coordinates of the options window client rectangle by calling <I>GetClientRect</I>. It then selects the stock object WHITE_BRUSH into this device context. Any subsequent graphics function calls that fill a rectangle or region will thus use white as the fill color.</P>
<P>The two <I>Rectangle</I> function calls result in the border being drawn. The first <I>Rectangle</I> call fills the entire client area of the options window with white. The effect of the second <I>Rectangle</I> call is to draw the black inset border. This happens for two reasons. First, the <I>InflateRect</I> call decreases the dimensions of the rectangle to be drawn. Second, the outline of a rectangle drawn by <I>Rectangle</I> is the color of the pen currently selected into the device context specified by the <I>hdc</I> parameter. Since this pen is black by default, the rectangle border is black.</P>
<P>Note that we have to make the first <I>Rectangle</I> call to fill the entire client area before drawing the inset border. Since the message handler code returns TRUE when it’s done, the default WM_ERASEBKGND processing is skipped. If the first <I>Rectangle</I> call is not made, only the inset rectangle would ever get drawn by our WM_ERASEBKGND message handler.</P>
<P><FONT SIZE="+1"><B><I>Creating and Drawing the Options Buttons</I></B></FONT></P>
<P>We’ve seen how the options window is created. But what about the three owner draw buttons that the window contains?
</P>
<P>The three owner draw buttons in the options window are created in response to the WM_CREATE message sent to <I>OptionsWndProc</I>:</P>
<!-- CODE //-->
<PRE>
/* Global variables and child control
identifiers defined in kiosk.h */
#define IDC_BALANCE 1028
#define IDC_DEPOSIT 1029
#define IDC_WITHDRAW 1030
HDC hdcButtons;
HBITMAP hBmpButtons;
HWND hwndBalance;
HWND hwndDeposit;
HWND hwndWithdraw;
LRESULT CALLBACK OptionsWndProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
HDC hdc;
UINT nID;
RECT rc;
switch(message)
{
case WM_CREATE:
hdc = GetDC(hwnd);
hdcButtons = CreateCompatibleDC(hdc);
hBmpButtons = LoadBitmap(ghInst,
MAKEINTRESOURCE(IDB_BALANCE));
SelectObject(hdcButtons, hBmpButtons);
ReleaseDC(hwnd, hdc);
hwndBalance = CreateWindow(TEXT("BUTTON"), NULL,
WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,
…,
(HMENU)IDC_BALANCE,…);
hwndDeposit = CreateWindow(TEXT("BUTTON"), NULL,
WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,
…,
(HMENU)IDC_DEPOSIT,…);
hwndWithdraw = CreateWindow(TEXT("BUTTON"), NULL,
WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,
…,
(HMENU)IDC_WITHDRAW,…);
return (0);
//Other message handlers
//…
default:
return (DefWindowProc(hwnd, message, wParam, lParam));
} //End of switch(message) statement
}
</PRE>
<!-- END CODE //-->
<P>The WM_CREATE handler does more than just create the three owner draw buttons. It also loads the bitmap containing the button images and selects that bitmap into a global memory device context called <I>hdcButtons</I>.</P>
<P>The button images are stored in one bitmap as shown in Figure 9.5. Each button has a pair of 48-pixel-wide images. The first image in the pair is used to draw the button’s unpressed state. The second is used to draw its pressed state.</P>
<P><A NAME="Fig5"></A><A HREF="javascript:displayWindow('images/09-05.jpg',290,55 )"><IMG SRC="images/09-05t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-05.jpg',290,55)"><FONT COLOR="#000077"><B>Figure 9.5</B></FONT></A> Options window button image bitmap.<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="266-269.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="272-274.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 + -