📄 090-093.html
字号:
<!--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=090-093//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="087-090.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="093-097.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Loading and Translating Accelerators</B></FONT></P>
<P>To use keyboard accelerators, an application must load the accelerator table resource. Windows CE represents keyboard accelerators using an <I>accelerator handle</I> of type HACCEL.</P>
<P>Accelerators are loaded using the <I>LoadAccelerators</I> function:</P>
<!-- CODE SNIP //-->
<PRE>
LoadAccelerators(hInstance, lpTableName);
</PRE>
<!-- END CODE SNIP //-->
<P><I>hInstance</I> specifies the application instance or dynamic link library instance that contains the accelerator table resource. <I>lpTableName</I> is the name of the accelerator table resource. If the accelerator table was given a string name when it was defined in the resource file, this is the string that you pass to <I>lpTableName</I>.</P>
<P>If, on the other hand, the table is identified by a resource identifier, you can use the Windows CE macro MAKEINTRESOURCE to convert the identifier into the suitable string value. For example, CMDBAR.EXE loads its accelerators as follows:</P>
<!-- CODE SNIP //-->
<PRE>
#define IDR_ACCELERATOR 102
HACCEL hAccel;
hAccel = LoadAccelerators(hInstance,
MAKEINTRESOURCE(IDR_ACCELERATOR));
</PRE>
<!-- END CODE SNIP //-->
<P>If <I>LoadAccelerators</I> is able to load the accelerator table, it returns a handle to the table. Otherwise the function returns NULL.</P>
<P>Once an accelerator table is loaded, an application needs to know how to respond to accelerator keystrokes. This is done by the function <I>TranslateAccelerator</I>:</P>
<!-- CODE SNIP //-->
<PRE>
TranslateAccelerator(hWnd, hAccelTable, lpMsg);
</PRE>
<!-- END CODE SNIP //-->
<P>The parameters passed to <I>TranslateAccelerator</I> are an HWND, an accelerator table (HACCEL), and a pointer to a message structure. The function first determines if the message specified by <I>lpMsg</I> is a WM_KEYDOWN or WM_SYSKEYDOWN message. If it is, it looks in the accelerator table specified by <I>hAccelTable</I> to see if the virtual key code sent with the message corresponds to any of the accelerator keys. If so, the message is converted into a WM_COMMAND message and sent to the window procedure of the window specified by the <I>hWnd</I> parameter, and then returns TRUE. Otherwise <I>TranslateAccelerator</I> returns FALSE.</P>
<P>So how does an application use this function to continually monitor the keyboard for accelerator keystrokes?</P>
<P>Handling accelerators is generally done by modifying an application’s message loop. Consider what happens when the standard message loop code is changed by first checking for accelerators:</P>
<!-- CODE SNIP //-->
<PRE>
while (GetMessage(&msg, NULL, 0, 0) == TRUE)
{
if (!TranslateAccelerator(hwndMain, hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
</PRE>
<!-- END CODE SNIP //-->
<P>As described above, <I>TranslateAccelerator</I> turns any WM_KEYDOWN or WM_SYSKEYDOWN message that corresponds to an accelerator into the equivalent WM_COMMAND message and sends it off to the appropriate window procedure. For every message that gets into the application’s message queue, this new message loop code first gives <I>TranslateAccelerator</I> a chance to process the message. If the message does not correspond to an accelerator keystroke (i.e., if <I>TranslateAccelerator</I> returns FALSE,) the message is processed in the usual way by <I>TranslateMessage</I> and <I>DispatchMessage</I>.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B><B><SMALL>COMPATIBILITY</SMALL>: WM_SYSCOMMAND M<SMALL>ESSAGES</SMALL></B>
<P><B>Unlike on desktop versions of Windows, under Windows CE <I>TranslateAccelerator</I> does not generate WM_SYSCOMMAND messages, only WM_COMMAND messages.</B><HR></FONT>
</BLOCKQUOTE>
</P>
<H3><A NAME="Heading11"></A><FONT COLOR="#000077">Using the Window Menu</FONT></H3>
<P>The window menu (or system menu, as it used to be called) is the little menu that appears in some windows when you tap the window icon in the upper left corner of the title bar. A window with a window menu is shown in Figure 4.5.
</P>
<P><A NAME="Fig5"></A><A HREF="javascript:displayWindow('images/04-05.jpg',480,240 )"><IMG SRC="images/04-05t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/04-05.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 4.5</B></FONT></A> A Windows CE window (system) menu.</P>
<P>You include a window menu in a window by specifying the WS_SYSMENU style when the window is created:
</P>
<!-- CODE SNIP //-->
<PRE>
HWND hwndSysMenu; //Handle of window with a window menu
hwndSysMenu = CreateWindow(
TEXT("MyWndClass"),
TEXT("My Window"),
WS_VISIBLE|WS_OVERLAPPED|WS_SYSMENU,
...);
</PRE>
<!-- END CODE SNIP //-->
<P>The window menu notifies its parent window that an item has been selected from the window menu by sending WM_SYSCOMMAND messages to the window. This is analogous to the command bar menu behavior of sending WM_COMMAND messages when items are selected. Table 4.6 details the WM_SYSCOMMAND message parameters.
</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 4.6</B> WM_SYSCOMMAND Message Parameters
<TR>
<TH WIDTH="35%" ALIGN="LEFT">PARAMETER
<TH WIDTH="65%" ALIGN="LEFT">MEANING
<TR>
<TD VALIGN="TOP">wParam
<TD>Specifies the system command. Value can be SC_CLOSE or SC_KEYMENU.
<TR>
<TD VALIGN="TOP">LOWORD(lParam)
<TD>Specifies the x component of the point where the stylus tapped the screen if the menu item was selected with the stylus.
<TR>
<TD VALIGN="TOP">HIWORD(lParam)
<TD>Specifies the y component of the point where the stylus tapped the screen if the menu item was selected with the stylus.
</TABLE>
<P>The SC_CLOSE system command indicates that the Close item was selected from the window menu. SC_KEYMENU means that the menu has been activated by a keystroke.
</P>
<P>Notice in Figure 4.5 that including a system menu in a window also includes a Close button in the upper right corner of the title bar.</P>
<P>A window procedure should return zero for any WM_SYSCOMMAND message that is handled. All other WM_SYSCOMMAND messages should be passed on to <I>DefWindowProc</I>.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B><B>S<SMALL>YSTEM</SMALL> C<SMALL>OMMANDS</SMALL></B>
<P><B>Under Windows NT and Windows 98, there are many more possible system command values that can be sent with WM_SYSCOMMAND messages. Under Windows CE, only the SC_CLOSE and SC_KEYMENU values are supported.</B><HR></FONT>
</BLOCKQUOTE>
</P>
<H3><A NAME="Heading12"></A><FONT COLOR="#000077">The Complete Windows CE Menu API</FONT></H3>
<P>So far we have been describing menus that are created in Windows CE resource files. The typical use of menus has been to create the desired menu in a menu resource and then insert it into a command bar with <I>CommandBar_InsertMenubar</I>. The application then responds to menu item selections with the appropriate WM_COMMAND message handler.</P>
<P>Windows CE also provides a rich set of functions for working with menus more directly. This API is very similar to the traditional Win32 menu API. Since there are already numerous resources that describe these functions in detail, this section will simply summarize the Windows CE menu API and point out where particular functions differ from their Win32 siblings. We also demonstrate some of the functions by showing how to add a context-specific pop-up menu to the CMDBAR.EXE sample application.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="087-090.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="093-097.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 + -