📄 275-278.html
字号:
<!-- END LEFT NAV -->
<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=10//-->
<!--PAGES=275-278//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch09/272-274.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="278-282.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 10<BR>The Windows CE Custom Draw Service
</FONT></H2>
<P><BIG><BIG>W</BIG></BIG>e have seen how owner draw techniques allow applications to define the appearance of various Windows CE control types. For example, by simply adding the BS_OWNERDRAW style to a button, and responding appropriately to the WM_DRAWITEM message in the parent window procedure, an application can completely redefine the look and feel of the button.</P>
<P>Another programming option that provides even more flexibility for modifying the appearance of Windows CE controls is the <I>custom draw service</I>.</P>
<P>In some ways, the custom draw service functionality is very similar to the way that owner draw controls work. With owner draw buttons, the WM_PAINT message handler in the button window procedure sends a WM_DRAWITEM message to the button’s parent and skips doing the default button painting operations. Similarly, controls that support the custom draw service send WM_NOTIFY messages to their parents at various times throughout their painting process. The custom draw service is more flexible because it provides more hooks for the parent window to influence the look of the control.</P>
<P>The custom draw service is supported by the following Windows CE common controls, which live in COMMCTRL.DLL. It is not supported by any of the child controls.</P>
<DL>
<DD><B>•</B> command bands
<DD><B>•</B> header controls
<DD><B>•</B> list view controls
<DD><B>•</B> toolbars
<DD><B>•</B> trackbar controls
<DD><B>•</B> tree view controls
</DL>
<P>In this chapter, we describe how to use the custom draw service through the example of a custom trackbar control. The control that results is shown in Figure 10.1. (I did not originally set out to try and make this control look like a thermometer!) Compare this to the standard trackbar control shown in Figure 10.2. The custom drawn version of the control demonstrates quite a bit of customization. The trackbar border appears rounded, with nice drop shadowing. The thumb, which is a little black dot, looks totally different from the standard trackbar thumb. And the channel, the area that the thumb gets dragged around in, is different.
</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/10-01.jpg',480,239 )"><IMG SRC="images/10-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/10-01.jpg',480,239)"><FONT COLOR="#000077"><B>Figure 10.1</B></FONT></A> A trackbar control drawn using the custom draw service.</P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/10-02.jpg',480,240 )"><IMG SRC="images/10-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/10-02.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 10.2</B></FONT></A> A standard trackbar control.</P>
<P>The application source code that implements this example is found in \Samples\custdraw on the companion CD. The resulting executable is called CUSTDRAW.EXE. To exit the application, tap any part of the main window’s client area not covered by the trackbar.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>AFTER COMPLETING THIS CHAPTER YOU WILL KNOW HOW TO …</B>
<P><B>Use the custom draw service to customize the appearance of Windows CE common controls</B><HR></FONT>
</BLOCKQUOTE>
</P>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Custom Draw Notification</FONT></H3>
<P>Windows CE controls that support the custom draw service give their parents the opportunity to customize the control drawing process at various times during the control’s <I>paint cycle</I>.</P>
<P>The paint cycle is defined as all processing that a control (or any window, for that matter) performs in response to the WM_ERASEBKGND and WM_PAINT messages. WM_ERASEBKGND is sent to a window when the window background needs to be erased in preparation for painting. WM_PAINT is sent when a window is asked to repaint itself.</P>
<P>Controls using the custom draw service give their parent windows the opportunity to handle parts of the drawing process by sending the NM_CUSTOMDRAW notification. This notification is sent in the form of a WM_NOTIFY message. The parameters sent with the WM_NOTIFY message are described in Table 10.1.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 10.1</B> Custom Draw Service WM_NOTIFY Message Parameters
<TR>
<TH WIDTH="40%" ALIGN="LEFT">PARAMETER
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD VALIGN="TOP">wParam
<TD>Integer containing the command identifier of the control sending the WM_NOTIFY message.
<TR>
<TD VALIGN="TOP">lParam
<TD>Pointer to an NMCUSTOMDRAW structure. If a tree view control sends the message, this parameter is an NMTVCUSTOMDRAW pointer. If the control is a list view control, this parameter is an NMLVCUSTOMDRAW pointer.
</TABLE>
<P>For list view and tree view controls, the first member of the structure pointed to by <I>lParam</I> is an NMCUSTOMDRAW structure.</P>
<P>The NMCUSTOMDRAW structure contains information about the control and where the control is in its paint cycle:</P>
<!-- CODE //-->
<PRE>
typedef struct tagNMCUSTOMDRAWINFO
{
NMHDR hdr;
DWORD dwDrawStage;
HDC hdc;
RECT rc;
DWORD dwItemSpec;
UINT uItemState;
LPARAM lItemlParam;
} NMCUSTOMDRAW, FAR* LPNMCUSTOMDRAW;
</PRE>
<!-- END CODE //-->
<P>The <I>hdr</I> member of this structure is an NMHDR notify message header structure that always accompanies common control notifications. <I>hdc</I> is the device context of the control, and <I>rc</I> is supposed to contain the control’s bounding rectangle. See the tip “Bogus NMCUSTOMDRAW rc Member” later in this chapter.</P>
<P><I>dwDrawStage</I> tells your application what stage of the drawing process the custom draw control is in. This member can be one of eight values. The first four specify the state that the paint cycle of the control is in. These are referred to as <I>global</I> draw stages:</P>
<DL>
<DD><B>CDDS_PREPAINT.</B> Sent before the control’s WM_PAINT handler begins.
<DD><B>CDDS_POSTPAINT.</B> Sent after the control’s WM_PAINT processing is complete.
<DD><B>CDDS_PREERASE.</B> Sent before the control’s WM_ERASEBKGND handler begins. Not currently supported.
<DD><B>CDDS_POSTERASE.</B> Sent after the control’s WM_ERASEBKGND processing is complete. Not currently supported.
</DL>
<P>Note that CDDS_PREERASE and CDDS_POSTERASE are not currently supported.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch09/272-274.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="278-282.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 + -