📄 250-253.html
字号:
<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=9//-->
<!--PAGES=250-253//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="247-250.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="253-257.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">The Anatomy of a Windows CE Control</FONT></H3>
<P>Understanding owner draw buttons and how to use them will be easier if we first look at how Windows CE controls such as buttons are implemented.
</P>
<P>In each of the sample applications that we have encountered in this book, we have created and registered a window class. This window class has described some of the visual aspects of the main application window, as well as the behavior of the main window by means of the window procedure assigned to the window class. In each of the sample applications, we have created just one instance of this window class. But there is nothing stopping us from using this main window’s window class to create multiple instances of the window class, each with a different set of window styles, dimensions, window caption text, and the like.</P>
<P>Windows CE controls are used in exactly this way. Each control in a Windows CE application is just a special type of window. Windows CE controls have their own window classes, and hence, their own window procedures controlling their behavior and appearance.</P>
<P>Let’s look at the button control class in closer detail. Deep in the implementation of the Windows CE Graphics, Windowing, and Events Subsystem (GWES) lives the implementation of the Windows CE button control class. Somewhere in the GWES code the button class is defined, and registered with a call to <I>RegisterClass</I>, just as you register your own window classes in your applications. The button class that gets registered includes a window procedure that implements all of the behavior of every button that appears in any Windows CE application.</P>
<P>The default appearance of buttons, a gray rectangle with text, is implemented by the button class window procedure’s WM_PAINT message handler. What happens when you press or release a button is dictated by the WM_LBUTTONDOWN and WM_LBUTTONUP handling code.</P>
<P>When you create a button control, you specify the button class name in the <I>CreateWindow</I> (or <I>CreateWindowEx</I>) call:</P>
<!-- CODE SNIP //-->
<PRE>
HWND hwndButton;
hwndButton = CreateWindow(TEXT("BUTTON"),…);
</PRE>
<!-- END CODE SNIP //-->
<P>This tells Windows CE to create an instance of the window class identified by the Unicode string “BUTTON”. All messages sent to <I>hwndButton</I> are thus handled by the window procedure identified by that window class. Hence, <I>hwndButton</I> knows how to walk and talk like a button control.</P>
<P>When a button needs to be repainted, the button class window procedure does all of the work. This is how Windows CE provides the default appearance and behavior of buttons and all other child or common controls.</P>
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">How Owner Draw Buttons Are Different</FONT></H3>
<P>Owner draw buttons work almost exactly like other Windows CE controls just described. The only difference is that the button control’s parent window, not the button, is responsible for defining the appearance of the button.
</P>
<P>An owner draw button behaves in all other ways like a non–owner draw button. For example, it still sends WM_COMMAND messages to its parent when pressed. The difference is that in the case of an owner draw button, the button skips its default WM_PAINT processing and instead sends its parent a WM_DRAWITEM message. The window procedure of the button’s parent responds to this message by drawing the button.</P>
<P><FONT SIZE="+1"><B>The BS_OWNERDRAW Style</B></FONT></P>
<P>An application tells Windows CE that a particular button is an owner draw button by specifying the BS_OWNERDRAW style when the button is created:
</P>
<!-- CODE SNIP //-->
<PRE>
#define IDC_BUTTON
HWND hwndButton;
hwndButton = CreateWindow(TEXT("Button"),
TEXT("Some Caption"),
WS_VISIBLE|WS_CHILD|
BS_OWNERDRAW,
...);
</PRE>
<!-- END CODE SNIP //-->
<P><FONT SIZE="+1"><B>The WM_DRAWITEM Message</B></FONT></P>
<P>To Windows CE, the button <I>hwndButton</I> is like any other button except that it has the BS_OWNERDRAW style bit set. The button class window procedure checks for this style when a button is about to be painted. If this style bit is set, the default painting is skipped, and the button sends a WM_DRAWITEM message to its parent.</P>
<P>The WM_DRAWITEM message is sent when an owner draw button must be repainted for any reason. This includes when the button is pressed, released, or receives focus. How a window responds to the WM_DRAWITEM message completely defines how owner draw buttons appear to the user.</P>
<P>A window may contain more than one owner draw button. Each of these buttons may have a completely different appearance. The WM_DRAWITEM message contains information about which button is sending the message so that the parent window can execute the appropriate drawing code. Table 9.1 gives the WM_DRAWITEM message parameter details.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 9.1</B> The WM_DRAWITEM Message
<TR>
<TH WIDTH="40%" ALIGN="LEFT">PARAMETER
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD>(UINT)wParam
<TD>Command identifier of the button sending the message.
<TR>
<TD VALIGN="TOP">(LPDRAWITEMSTRUCT)lParam
<TD>Pointer to a DRAWITEMSTRUCT structure containing information about the control to be drawn.
</TABLE>
<P>The <I>wParam</I> value tells the parent window which of the owner draw buttons that it contains needs to be redrawn. The DRAWITEMSTRUCT pointed to by the <I>lParam</I> contains all of the information about the control and why it must be redrawn.</P>
<P>Applications should return TRUE when they finish processing the WM_DRAWITEM message.</P>
<P>The DRAWITEMSTRUCT structure is defined as:</P>
<!-- CODE //-->
<PRE>
typedef struct tagDRAWITEMSTRUCT
{
UINT CtlType;
UINT CtlID;
UINT itemID;
UINT itemAction;
UINT itemState;
HWND hwndItem;
HDC hDC;
RECT rcItem;
DWORD itemData;
} DRAWITEMSTRUCT, *PDRAWITEMSTRUCT, *LPDRAWITEMSTRUCT;
</PRE>
<!-- END CODE //-->
<P>The first two members define the type of the control and its identifier.
</P>
<P>The <I>hwndItem</I> member contains the window handle of the button that sent the WM_DRAWITEM message. Similarly, <I>hDC</I> is the button’s device context. Any drawing operations performed to render the appearance of the button should be done in this device context.</P>
<P><I>rcItem</I> contains the rectangular dimensions of the button in client coordinates.</P>
<P>The <I>itemData</I> member only has meaning with owner draw list boxes and combo boxes. It therefore has no meaning under Windows CE, which does not support owner draw list boxes or combo boxes.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="247-250.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="253-257.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 + -