📄 225-231.html
字号:
<!-- 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=8//-->
<!--PAGES=225-231//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="221-225.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="231-234.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B><I>Adding and Removing Subkeys</I></B></FONT></P>
<P>You add and remove registry subkeys via the Remote Registry Editor just as you would with regedit on Windows NT.
</P>
<P>For example, let’s say you want to add a subkey called Applications under the My Emulation\HKEY_LOCAL_MACHINE key that is shown in Figure 8.2. To do this, expand the My Emulation node, and then expand the HKEY_LOCAL_MACHINE node. To add the Applications subkey, tap the HKEY_LOCAL_MACHINE key icon so that it is selected, and then select the New Key menu option from the Edit menu as shown in Figure 8.3.</P>
<P><A NAME="Fig3"></A><A HREF="javascript:displayWindow('images/08-03.jpg',538,293 )"><IMG SRC="images/08-03t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/08-03.jpg',538,293)"><FONT COLOR="#000077"><B>Figure 8.3</B></FONT></A> The New Key menu option.</P>
<P>As a result of this operation, the New Key dialog box shown in Figure 8.4 appears. Type “Applications”, the name of the new subkey, in the edit field in this dialog box and press OK. The new subkey is then created under the HKEY_LOCAL_MACHINE key as shown in Figure 8.5.
</P>
<P><A NAME="Fig4"></A><A HREF="javascript:displayWindow('images/08-04.jpg',538,293 )"><IMG SRC="images/08-04t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/08-04.jpg',538,293)"><FONT COLOR="#000077"><B>Figure 8.4</B></FONT></A> The New Key dialog box.</P>
<P><A NAME="Fig5"></A><A HREF="javascript:displayWindow('images/08-05.jpg',538,376 )"><IMG SRC="images/08-05t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/08-05.jpg',538,376)"><FONT COLOR="#000077"><B>Figure 8.5</B></FONT></A> The newly created Applications subkey.</P>
<P>To delete a subkey, simply tap on the subkey icon and choose the Delete option from the Remote Registry Editor Edit menu. Alternatively, pressing the Delete key will also delete the selected subkey.
</P>
<P><FONT SIZE="+1"><B><I>Adding and Removing Subkey Values</I></B></FONT></P>
<P>Registry values are added to the registry (for either Windows NT or CE emulation) in much the same way as subkeys are added. Instead of selecting the New Key menu option, you choose one of the other four New menu options (see Figure 8.3). Each of these options specifies that you want to create a value under the currently selected registry subkey. The data type of the new value is the type specified by the selected menu option.
</P>
<P>For example, if you want to add a DWORD value called AppCount to the Applications subkey we created in the previous section, select the Applications and then select the New DWORD Value menu option from the Edit menu. The dialog box shown in Figure 8.6 will appear. Type the name of the new value and the initial value it contains in the corresponding text fields as shown. Press the OK button, and the new value appears in the right-hand pane of the Remote Registry Editor as shown in Figure 8.7.</P>
<P><A NAME="Fig6"></A><A HREF="javascript:displayWindow('images/08-06.jpg',538,376 )"><IMG SRC="images/08-06t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/08-06.jpg',538,376)"><FONT COLOR="#000077"><B>Figure 8.6</B></FONT></A> The new DWORD value dialog box.</P>
<P><A NAME="Fig7"></A><A HREF="javascript:displayWindow('images/08-07.jpg',538,376 )"><IMG SRC="images/08-07t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/08-07.jpg',538,376)"><FONT COLOR="#000077"><B>Figure 8.7</B></FONT></A> The newly created AppCount value.</P>
<P>Like registry subkeys, registry values are deleted by selecting the particular value and then choosing the Delete menu option from the Edit menu. Alternatively, pressing the Delete key will also delete the selected value.
</P>
<P>The Remote Registry Editor also contains menu options for copying and renaming subkeys and values, as well as for generating registry files from the contents of the registry.</P>
<P><FONT SIZE="+1"><B>A Note on Registry Function Return Values</B></FONT></P>
<P>The various Windows CE registry API functions return ERROR_SUCCESS if they succeed. If a particular function fails, you might expect to call <I>GetLastError</I> in order to get additional clues as to why your function call failed.</P>
<P>Unfortunately, the registry functions do not set the current error code on failure with a call to <I>SetLastError</I>. Therefore, calling <I>GetLastError</I> tells you nothing in these cases.</P>
<P>The possible error return values are those defined in WINERROR.H. You can use the <I>FormatMessage</I> function with the FORMAT_MESSAGE_FROM_SYSTEM flag set in the <I>dwFlags</I> parameter to get the message text of the error.</P>
<P>Alternatively, you can use my preferred (and quicker) method: Keep WINERROR.H open in your editor while debugging your registry calls and search for the error codes manually!</P>
<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Creating and Opening Registry Keys</FONT></H3>
<P>The Windows CE registry API provides functions for both creating new registry keys and opening existing keys.
</P>
<P>An application creates a registry key with <I>RegCreateKeyEx</I>. This function will create a new key in the registry if the specified key does not exist. If the key already exists, <I>RegCreateKeyEx</I> opens the key.</P>
<!-- CODE SNIP //-->
<PRE>
RegCreateKeyEx(hKey, lpszSubKey, Reserved, lpszClass,
dwOptions, samDesired, lpSecurityAttributes,
phkResult, lpdwDisposition);
</PRE>
<!-- END CODE SNIP //-->
<P>It is easiest to discuss this function if we start by describing the <I>phkResult</I> parameter. This is a pointer to an HKEY, which is returned by <I>RegCreateKeyEx</I>. It is the key of the newly created or opened registry key.</P>
<P>The <I>hKey</I> parameter is one of the primary keys, such as HKEY_ LOCAL_MACHINE, or the HKEY of some other registry key that the application has opened. <I>lpszSubKey</I> is the null-terminate string name of the subkey to create or open. This parameter cannot be NULL, implying that the result of <I>RegCreateKeyEx</I>, <I>phkResult</I>, is always a subkey of <I>hKey</I>.</P>
<P>The result of a <I>RegCreateKeyEx</I> call can be used to create subkeys of the key created in the first call. For example, assume we wish to create the two subkeys named HKEY_LOCAL_MACHINE\MyKeys and HKEY_LOCAL_MACHINE\MyKeys\Data. The following code would do the trick:</P>
<!-- CODE //-->
<PRE>
HKEY hMyKeys, hData;
//Create HKEY_LOCAL_MACHINE\MyKeys
RegCreateKeyEx(
HKEY_LOCAL_MACHINE, //Primary key
TEXT("MyKeys"), //Subkey Name
..., //Parameters we’ve
//yet to discuss
&hMyKeys, //i.e., phkResult
...);
//Using previous result, create the key
//HKEY_LOCAL_MACHINE\MyKeys\Data
RegCreateKeyEx(
hMyKeys, //HKEY_LOCAL_MACHINE\MyKeys
TEXT("Data"), //Data subbkey
...,
&hData, //Handle to Data subkey
...);
</PRE>
<!-- END CODE //-->
<P>The <I>Reserved</I> parameter of <I>RegCreateKeyEx</I> is just that, reserved for future use by Windows CE. This parameter must be set to zero.</P>
<P><I>lpszClassName</I> is a null-terminated string containing the class of the key to be opened or created. If you are not interested in assigning a class name, this parameter can be NULL.</P>
<P>The parameters <I>dwOptions</I>, <I>samDesired</I>, and <I>lpSecurityAttributes</I> are ignored. <I>dwOptions</I> and <I>samDesired</I> should be zero, and <I>lpSecurityAttributes</I> should be NULL.</P>
<P>The final parameter, <I>lpdwDisposition</I>, is a DWORD pointer used as a return value which specifies whether the function created a new key or simply opened an existing key. The possible values returned are REG_CREATED_NEW_KEY and REG_OPENED_EXISTING_KEY.</P>
<P>Existing registry keys can alternatively be opened using <I>RegOpenKeyEx</I>:</P>
<!-- CODE SNIP //-->
<PRE>
RegOpenKeyEx(hKey, lpszSubKey, ulOptions, samDesired,
phkResult);
</PRE>
<!-- END CODE SNIP //-->
<P>As with <I>RegCreateKeyEx</I>, <I>hKey,</I> and <I>lpszSubKey</I> are the key and subkey of the key to open. In the case of <I>RegOpenKeyEx</I>, however, <I>lpszSubKey</I> can be NULL. <I>ulOptions</I> and <I>samDesired</I> are reserved and must be zero. <I>phkResult</I> is the same as in <I>RegCreateKeyEx</I>. It returns a handle to the opened key if <I>RegOpenKeyEx</I> is successful.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="221-225.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="231-234.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 + -