⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 253-257.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<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="">&nbsp;<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=253-257//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="250-253.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="257-259.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The two most important members of the DRAWITEMSTRUCT are <I>itemAction</I> and <I>itemState</I>. These members describe the drawing action that must be performed and the state of the button respectively. An application uses these values to determine how to draw the owner draw button. <I>itemAction</I> can be one or more of the following values (combined by a bitwise OR):</P>
<DL>
<DD><B>ODA_DRAWENTIRE.</B> The entire button must be redrawn.
<DD><B>ODA_FOCUS.</B> The button has lost or gained keyboard focus (as indicated by the <I>itemState</I> value).
<DD><B>ODA_SELECT.</B> The button selection status has changed (as indicated by the <I>itemState</I> value).
<BR><I>itemState</I> can be one or more of the following:
<DD><B>ODS_CHECKED.</B> Only used for owner draw menus; indicates the item is checked.
<DD><B>ODS_SELECTED.</B> The button is selected/pressed.
<DD><B>ODS_GRAYED.</B> Only used for owner draw menus; indicates the item is to be grayed.
<DD><B>ODS_DISABLED.</B> The button is to be drawn as disabled.
<DD><B>ODS_FOCUS.</B> The button has the keyboard focus.
</DL>
<P>Application programmers typically just use the <I>itemState</I> value to determine how to draw their own draw buttons. Since <I>itemAction</I> only indicates which of the <I>itemState</I> values to be on the lookout for, it is easiest to just test <I>itemState</I>.</P>
<P><FONT SIZE="+1"><B><I>An Example</I></B></FONT></P>
<P>How does all of this get used in practice? Let&#146;s take a simple example and demonstrate how a parent window would respond to the WM_DRAWITEM message. Assume that the parent window wants to create an owner draw button with a control identifier defined as IDC_BUTTON and the string &#147;Press Here&#148; as the button text. When the button is unpressed, it appears as shown in Figure 9.1. Figure 9.2 shows the button in the pressed state.
</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/09-01.jpg',480,240 )"><IMG SRC="images/09-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-01.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 9.1</B></FONT></A>&nbsp;&nbsp; Sample owner draw button in the unpressed state.</P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/09-02.jpg',480,240 )"><IMG SRC="images/09-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-02.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 9.2</B></FONT></A>&nbsp;&nbsp; Sample owner draw button in the pressed state.</P>
<P>The button is created by the code shown below. <I>hwndMain</I> and <I>hInstance</I> are the application main window and application instance, respectively.</P>
<!-- CODE SNIP //-->
<PRE>
  #define IDC_BUTTON  1028
  HWND hwndButton;
  hwndButton = CreateWindow(TEXT("BUTTON"),
     TEXT("Press Here"),
     WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,
     175,50,100,100,hwndMain,
     (HMENU)IDC_BUTTON,
     hInstance, NULL);
</PRE>
<!-- END CODE SNIP //-->
<P>The WM_DRAWITEM code to implement the button appearance, which appears in the button parent window&#146;s window procedure, is shown below. Only the part of the window procedure relevant to drawing the owner draw buttons is included here.
</P>
<!-- CODE //-->
<PRE>
  LRESULT CALLBACK WndProc(HWND hwnd,
               UINT message,
               WPARAM wParam,
               LPARAM lParam)
  &#123;
     UINT nID;
     switch(message)
     &#123;
     /* Other message handlers here&#133; */
     case WM_DRAWITEM:
      UINT nID;
      LPDRAWITEMSTRUCT lpdis;
      nID = (UINT)wParam;
      switch (nID)
      &#123;
      case IDC_BUTTON:
       HDC hdc;
       RECT rc;
       HBRUSH hBrushOld;
       HPEN hPenOld;
       int nModeOld;
       TCHAR pszText[129];
       lpdis = (LPDRAWITEMSTRUCT)lParam;
       rc = lpdis-&gt;rcItem;
       hdc = lpdis-&gt;hDC;
       if (lpdis-&gt;itemState &#38; ODS_SELECTED)
       &#123;
        //Invert the button when selected
        PatBlt(hdc, rc.left,rc.top,
         rc.right,rc.bottom, DSTINVERT);
       &#125;
       else
       &#123;
        //Draw the button in its unpressed state
        hPenOld = (HPEN)SelectObject(hdc,
         GetStockObject(BLACK_PEN));
        hBrushOld = (HBRUSH)SelectObject(hdc,
         GetStockObject(WHITE_BRUSH));
        nModeOld = SetBkMode(hdc, TRANSPARENT);
        Rectangle(hdc, rc.left,rc.top,
         rc.right,rc.bottom);
        GetWindowText(lpdis-&gt;hwndItem,
         pszText, 129);
        DrawText(hdc, pszText, -1, &#38;rc,
         DT_CENTER|DT_VCENTER);
        SetBkMode(hdc, nModeOld);
        SelectObject(hdc, hBrushOld);
        SelectObject(hdc, hPenOld);
       &#125;
       break;
      default:
       break;
      &#125;    //End of switch(nID) block
      return (TRUE);
     /* Other message handlers here&#133; */
     &#125;       //End of switch(message) block
  &#125;
</PRE>
<!-- END CODE //-->
<P>The WM_DRAWITEM handler contains a switch statement for determining which owner draw button is responsible for sending the WM_DRAWITEM message. Although this example only contains one owner draw button, it is a good practice to put such a switch statement in your handler in case you add more owner draw buttons later.
</P>
<P>We need to draw the IDC_BUTTON button in the pressed and unpressed states. We check to see if the button is pressed with the following test:</P>
<!-- CODE SNIP //-->
<PRE>
   if (lpdis-&gt;itemState &#38; ODS_SELECTED)
</PRE>
<!-- END CODE SNIP //-->
<P>In other words, if the ODS_SELECTED flag is set in the DRAWITEMSTRUCT <I>itemState</I> member, the button is being pressed. Note that the test is not</P>
<!-- CODE SNIP //-->
<PRE>
   if (lpdis-&gt;itemState == ODS_SELECTED)
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="250-253.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="257-259.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>&nbsp;|&nbsp; <a href="/contactus.html"><font color="#006666">Contact Us</font></a>&nbsp;|&nbsp; <a href="/aboutus.html"><font color="#006666">About Us</font></a>&nbsp;|&nbsp; <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> &nbsp;|&nbsp; <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> &nbsp;|&nbsp; <a href="/"><font color="#006666">Home</font></a></b>
		<br><br>
		
		Use of this site is subject to certain <a href="/agreement.html">Terms &amp; Conditions</a>, <a href="/copyright.html">Copyright &copy; 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 + -