?? 069-072.html
字號:
</tr>
</table>
</form>
<!-- LEFT NAV SEARCH END -->
</td>
<!-- PUB PARTNERS END -->
<!-- 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=4//-->
<!--PAGES=069-072//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch03/066-068.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="072-075.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 4<BR>Menus and the Windows CE Command Bar
</FONT></H2>
<P><BIG><BIG>O</BIG></BIG>ne of the biggest challenges that Windows application programmers have traditionally faced is designing a user interface that is intuitive and easy to use. Keeping the computer screen organized and free of the clutter of lots of buttons and other controls gets more difficult as Windows programs become more complex and feature-rich.</P>
<P>If this is a challenge on desktop Windows platforms, it is even more problematic when designing applications for Windows CE-based devices. With screen sizes that are typically a mere fraction of their desktop computer siblings, Windows CE devices are much more susceptible to problems of screen clutter and confusing user interfaces.</P>
<P>Fortunately, Windows CE provides extensive support for including menus and menu accelerators in your applications. Menus provide the application programmer and user interface designer with a convenient way to include a large number of user command options in a small amount of screen real estate. Accelerators allow applications to translate simple keyboard actions into menu item equivalents. Of course, Windows CE devices are not required to have a keyboard. Palm-size PCs have no use for menu accelerators. But the support for accelerators is provided by Windows CE for use by those devices that do include a keyboard.</P>
<P>Central to the discussion of Windows CE menus is the command bar control. In this chapter we will introduce this control, which is used for holding menus as well as other child controls. Command bars give Windows CE application programmers a way to include menus and other controls in an application without using large amounts of screen space.</P>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">I Repeat Myself When under Stress …</FONT></H3>
<P>It cannot be stressed enough here that menus under Windows CE are fundamentally different from menus under Win32. Menus in Windows CE applications can still be defined in terms of menu resources just as they can on desktop Windows platforms. However, there is no concept of a menu bar, and Windows CE menus are not part of the non-client area of a window. Menus under Windows CE must be embedded within a control, most commonly a command bar. (Menus can also be inserted into command bands, a control discussed in the next chapter.) The controls that contain Windows CE menus are child controls, and therefore reside in their parent window’s client area.
</P>
<P>Another implication of the absence of menu bar support under Windows CE is that the <I>hMenu</I> parameter of <I>CreateWindow</I> and <I>CreateWindowEx</I> has no meaning for a top-level window. Therefore code like the following will fail:</P>
<!-- CODE //-->
<PRE>
HWND hwndMain;
HMENU hMenu;
/* Assume that IDR_MENU identifies a legitimate menu
resource contained by the module hInstance.
*/
hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU));
hwndMain = CreateWindow(
TEXT(“MYWNDCLASS”),
NULL,
WS_VISIBLE|WS_OVERLAPPED,
0,0,100,100,
NULL,
hMenu,
hInstance,
NULL);
</PRE>
<!-- END CODE //-->
<P><I>CreateWindow</I> in this case will most assuredly return NULL. Menus for top-level windows are not supported.</P>
<P>For the same reason, creating instances of a window class registered with a non-NULL <I>lpszMenuName</I> WNDCLASS member works, but the <I>lpszMenuName</I> attribute has no effect.</P>
<P>Of course you can still use non-NULL values for the <I>hMenu</I> parameter of <I>CreateWindow</I> and <I>CreateWindowEx</I> to specify the identifier of child windows. For example, as we saw in the previous chapter, whenever you create a Windows CE control, you use the <I>hMenu</I> parameter to specify that control’s identifier.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>AFTER COMPLETING THIS CHAPTER YOU WILL KNOW HOW TO …</B>
<DL>
<DD><B>Create a command bar control and insert it into a window</B>
<DD><B>Add a menu to a command bar</B>
<DD><B>Add controls like buttons and combo boxes to a command bar</B>
<DD><B>Add adornments to a command bar</B>
<DD><B>Add tool tips to a command bar</B>
<DD><B>Add menu accelerators to a command bar menu</B>
<DD><B>Add a window menu (system menu) to a window</B>
</DL>
<HR></FONT>
</BLOCKQUOTE>
<H3><A NAME="Heading3"></A><FONT COLOR="#000077">The Command Bar Control</FONT></H3>
<P>On desktop Windows platforms, menus are contained in a <I>menu bar</I>. Windows CE does not support the concept of a menu bar. Menus are instead contained by a Windows CE control called the <I>command bar</I> control.</P>
<P>One exception to this is pop-up menus. Pop-up menus in Windows CE are implemented just as they are on desktop Windows platforms. We will see an example using pop-up menus later in this chapter.</P>
<P>Command bars are one of the common controls. Their implementation lives in the COMMCTRL.DLL dynamic link library. To use them, an application must therefore initialize the common control library with a call to <I>InitCommonControls</I> or <I>InitCommonControlsEx</I>. Furthermore, applications must include the file COMMCTRL.H. This header file contains the definitions of the <I>InitCommonControls</I> and <I>InitCommonControlsEx</I> functions. It also defines all of the command bar API functions that we will use in this chapter.</P>
<P>Since command bars often contain menus, it is very easy to think of them as menu bars. But it is important to keep in mind that command bars, just like buttons or list boxes, are child controls. This means that a command bar is part of the client area of the window that owns it. Your application needs to account for the space used up by any command bars in the client area. The sidebar that follows points out a good way to do this.</P>
<P>Command bar controls are actually a type of toolbar control. As such, you can use any of the toolbar messages, styles, and the like with command bars. Toolbar messages can be sent directly using <I>SendMessage</I>. Toolbar styles can be added with <I>SetWindowLong</I>.</P>
<P>The details of creating and working with command bars will be introduced later. We first describe some menu basics. Because Windows CE menu concepts are similar to their desktop Windows counterparts, this discussion will be brief.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch03/066-068.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="072-075.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 + -