📄 075-078.html
字号:
<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=4//-->
<!--PAGES=075-078//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="072-075.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="078-080.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The general syntax of a menu resource is shown below. Items in uppercase are required keywords. Items in italics are supplied by the application programmer. Items in square brackets are optional values.
</P>
<!-- CODE //-->
<PRE>
MenuName MENU [DISCARDABLE]
BEGIN
POPUP SubMenu1Name [, options]
BEGIN
MENUITEM MenuItemName, id [, options]
... //More MENUITEMs
END
POPUP SubMenu2Name [, options]
BEGIN
MENUITEM MenuItemName, id [, options]
...
END
END
</PRE>
<!-- END CODE //-->
<P><I>MenuName</I> is the name of the menu. Generally this is a resource identifier, but it can be a string menu name.</P>
<P>The optional DISCARDABLE keyword tells Windows CE that the menu resource can be discarded from memory automatically when no longer needed.</P>
<P>The POPUP keyword indicates that a new submenu is being defined. These POPUP definitions define the individual submenus. <I>SubMenu1Name</I>, <I>SubMenu2Name</I>, etc. are the names of the submenus. In the example in Figure 4.1, these would be “&File” and “&Options”.</P>
<P>Cascading menus can be defined by nesting submenus within other submenus.</P>
<P>The MENUITEM keyword inserts a new item in the submenu. The <I>MenuItemName</I> values represent the individual pull-down menu choices.</P>
<P><I>id</I> is the <I>command identifier</I> for the particular menu item. The use of this identifier is described in the next section, where we describe how applications respond to menu item selections.</P>
<P>The menu resource identifier and menu item command identifiers are typically defined in the application’s RESOURCE.H file.</P>
<P>Various options can be specified for submenus and for menu items. More than one of these options can be specified by bitwise-ORing them together. For submenus, these option include:</P>
<DL>
<DD><B>GRAYED.</B> The text is grayed; the menu is inactive, and does not generate WM_COMMAND messages.
<DD><B>INACTIVE.</B> The text is displayed normally, but the menu is still inactive. No WM_COMMAND messages are generated.
<DD><B>MENUBREAK.</B> This option is supported, but has no effect in the context of menus in command bars.
<DD><B>HELP.</B> This option is supported, but has no effect in the context of menus in command bars.
</DL>
<P>Menu item options include the following:
</P>
<DL>
<DD><B>CHECKED.</B> Places a check mark to the left of the menu item text.
<DD><B>GRAYED.</B> Same meaning as for submenus; see the list above.
<DD><B>INACTIVE.</B> Same meaning as for submenus; see the list above.
<DD><B>MENUBREAK.</B> The menu item and all items that follow appear in a new column in the menu.
<DD><B>MENUBARBREAK.</B> Same as MENUBREAK, except that a vertical line separates the menu columns.
</DL>
<P>As an example, here is the menu resource definition for the cascading menu shown in Figure 4.2:
</P>
<!-- CODE //-->
<PRE>
IDR_MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Exit", IDC_EXIT
END
POPUP "&Options"
BEGIN
MENUITEM "&Empty Combo Box", IDC_EMPTY
MENUITEM "&Fill Combo Box" IDC_FILL
POPUP "&Cascade"
BEGIN
MENUITEM "Cascade Menu Item 1", IDC_SUBITEM1
MENUITEM SEPARATOR
MENUITEM "Cascade Menu Item 2", IDC_SUBITEM2
END
END
END
</PRE>
<!-- END CODE //-->
<P><FONT SIZE="+1"><B>Responding to Menu Items</B></FONT></P>
<P>The usefulness of menus comes from the ability to map the various menu items in a menu to actions. This is done by assigning a command identifier to each of the menu items that an application is meant to respond to. The previous section described how a command identifier is assigned to a menu item.
</P>
<P>This command identifier performs the same role as control identifiers for Windows CE controls. Specifically, whenever a menu item is selected, Windows CE sends a WM_COMMAND message to the parent of the command bar control. The low word of the <I>wParam</I> parameter contains the menu item identifier. The WM_COMMAND message notification code is zero, indicating that the message is sent as a result of a menu item selection.</P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">Creating a Command Bar</FONT></H3>
<P>Creating a command bar control is a little different from creating other Windows CE controls. Instead of using <I>CreateWindow</I> or <I>CreateWindowEx</I> as when creating child and common controls, Windows CE provides a separate API for creating and working with command bar controls.</P>
<P>To create a command bar control, an application calls <I>CommandBar_Create</I>:</P>
<!-- CODE SNIP //-->
<PRE>
CommandBar_Create(hInst, hwndParent, idCmdbar);
</PRE>
<!-- END CODE SNIP //-->
<P>This function is a wrapper for the <I>CreateWindow</I> call that ultimately creates the actual command bar window. <I>hInst</I> is the application instance of the application in which the control is being created. <I>hwndParent</I> is the command bar’s parent window. <I>idCmdBar</I> is the control identifier of the command bar.</P>
<P>If <I>CommandBar_Create</I> is successful, it returns the HWND of the newly created command bar control. Otherwise the function returns NULL. Thus creating a command bar is semantically similar to creating any other Windows CE window or control.</P>
<P>Creating the command bar control is only the beginning. The command bar in Figure 4.1 contains a menu and various child controls. After calling <I>CommandBar_Create</I>, your application is left with nothing more than the HWND of an empty command bar control.</P>
<P>Adding useful things like menus and buttons to a command bar control requires using the various <I>CommandBar_Insert</I> functions.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="072-075.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="078-080.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 + -