📄 285-287.html
字号:
</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=285-287//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="282-285.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="287-288.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">A Real Example</FONT></H3>
<P>Let’s look at the real CUSTDRAW.EXE example and see how the custom trackbar of Figure 10.1 is implemented.
</P>
<P>The trackbar parent window draws the channel and thumb itself. It also responds to the TBCD_TICS item spec to draw the rounded trackbar outline. The NM_CUSTOMDRAW notification handler looks like this:</P>
<!-- CODE //-->
<PRE>
#define IDC_TRACKBAR 1028
case WM_NOTIFY:
LPNMHDR lpnmhdr;
lpnmhdr = (LPNMHDR)lParam;
switch(lpnmhdr->code)
{
case NM_CUSTOMDRAW:
LPNMCUSTOMDRAW lpnmcd;
lpnmcd = (LPNMCUSTOMDRAW)lParam;
/* Respond to notification if it comes from the trackbar control.
*/
if (lpnmcd->hdr.idFrom==IDC_TRACKBAR)
{
BOOL bSel;
bSel = (lpnmcd->uItemState==CDIS_SELECTED);
switch(lpnmcd->dwDrawStage)
{
case CDDS_PREPAINT:
return (CDRF_NOTIFYITEMDRAW);
case CDDS_ITEMPREPAINT:
return (OnDrawTrackbar(
lpnmcd->hdr.hwndFrom,
lpnmcd->hdc,
lpnmcd->dwItemSpec,
bSel);
default:
return (CDRF_DODEFAULT);
} //End of switch(dwDrawStage) block
} //End of if (hwndTB) block
default:
return (0);
} //End of switch(lpnmhdr->code) block
</PRE>
<!-- END CODE //-->
<P>The trackbar control’s parent window tests to see if the NM_CUSTOMDRAW notification is sent by the trackbar. This is done by comparing the trackbar command identifier IDC_TRACKBAR to the NMHDR <I>idFrom</I> value:</P>
<!-- CODE SNIP //-->
<PRE>
if (lpnmcd->hdr.idFrom==IDC_TRACKBAR)
</PRE>
<!-- END CODE SNIP //-->
<P>The next thing the code does is obtain the current item state. If you run the CUSTDRAW.EXE application and press the trackbar thumb, the black dot changes to gray. In order to do this, the application needs to know if the thumb is selected.
</P>
<P>After that, the code proceeds as in the general NM_CUSTOMDRAW notification handler presented earlier. It returns CDRF_NOTIFYITEMDRAW in response to the CDDS_PREPAINT notification. This ensures that the trackbar control sends further paint cycle notifications. In response to the individual CDDS_ITEMPREPAINT notifications, the code performs the custom trackbar drawing operations as implemented by the application function <I>OnDrawTrackbar</I>:</P>
<!-- CODE //-->
<PRE>
int OnDrawTrackbar(HWND hwnd,
HDC hdc,
DWORD dwItemSpec,
BOOL bSelected)
{
HBRUSH hBrushOld;
RECT rc, rcChannel;
int nRes;
int nHeight, nCenter;
/* Calculate the custom channel RECT */
GetClientRect(hwnd, &rc);
nHeight = (rc.bottom-rc.top);
nCenter = rc.top+nHeight/2;
SendMessage(hwnd, TBM_GETCHANNELRECT, 0,
(LPARAM)&rcChannel);
rcChannel.top = nCenter-12;
rcChannel.bottom = rcChannel.top+12;
switch(dwItemSpec)
{
case TBCD_THUMB:
SendMessage(hwnd, TBM_GETTHUMBRECT, 0, (LPARAM)&rc);
rc.top = rcChannel.top+1;
rc.bottom = rcChannel.bottom-1;
if (!bSelected)
{
hBrushOld = (HBRUSH)SelectObject(hdc,
GetStockObject(BLACK_BRUSH));
}
else
{
hBrushOld = (HBRUSH)SelectObject(hdc,
GetStockObject(LTGRAY_BRUSH));
}
RoundRect(hdc, rc.left, rc.top,
rc.right, rc.bottom, 20, 20);
nRes = CDRF_SKIPDEFAULT;
break;
case TBCD_CHANNEL:
hBrushOld = (HBRUSH)SelectObject(hdc,
GetStockObject(WHITE_BRUSH));
Rectangle(hdc, rcChannel.left, rcChannel.top,
rcChannel.right, rcChannel.bottom);
nRes = CDRF_SKIPDEFAULT;
break;
case TBCD_TICS:
/* Tic marks get drawn first. Therefore draw the
entire control outline here, so that it doesn’t
wipe out any subsequent painting.
*/
GetClientRect(hwnd, &rc);
//First draw a black filled round rectangle
hBrushOld = (HBRUSH)SelectObject(hdc,
GetStockObject(BLACK_BRUSH));
RoundRect(hdc, rc.left, rc.top,
rc.right, rc.bottom, 20, 20);
/* Next inset the rectangle slightly, and fill
it with white to leave behind the black
"drop shadow" outline.
*/
SelectObject(hdc,GetStockObject(WHITE_BRUSH));
rc.bottom—;
rc.right—;
RoundRect(hdc, rc.left, rc.top,
rc.right, rc.bottom, 20, 20);
nRes = CDRF_DODEFAULT;
break;
} //End of switch(dwItemSpec) statement
SelectObject(hdc, hBrushOld);
return (nRes);
}
</PRE>
<!-- END CODE //-->
<P>This function is responsible for drawing all of the trackbar control components. As parameters it takes the control HWND and HDC. It also takes the NMCUSTOMDRAW <I>dwItemSpec</I> value to specify which part of the control is to be drawn. Finally, it takes a BOOL indicating if the part of the control specified in the <I>dwItemSpec</I> parameter is selected.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="282-285.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="287-288.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 + -