📄 063-066.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=3//-->
<!--PAGES=063-066//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="059-063.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="066-068.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><I>lpstrFilter</I> is used to specify the <I>filter strings</I> to be used when displaying the dialog box. These strings determine the contents of the Type: combo box (see Figure 3.4). They also tell the dialog box to display only those files with the specified extensions. This member can be NULL. You specify <I>lpstrFilter</I> as pairs of NULL-terminated strings. The first string in each pair is the descriptive text, such as the text “Text Files (*.txt)” that appears in the Type: field in Figure 3.4. The second string is the filter pattern, such as “*.htm”.</P>
<P><I>lpstrCustomFilter</I> is used by <I>GetOpenFileName</I> or <I>GetSaveFileName</I> to return the filter chosen by the user. This can be NULL. If not NULL, you must specify the length of the buffer that you are passing in the <I>lpstrCustomFilter</I> member in the <I>nMaxCustFilter</I> member.</P>
<P><I>nFilterIndex</I> specifies the 1-based index of the pair of <I>lpstrFilter</I> strings with which to initialize the Type: combo box.</P>
<P><I>lpstrFile</I> is used to specify the file name to initially display in the Name field. It also returns the name of the file specified by the user if the user presses the OK button.</P>
<P><I>nMaxFile</I> specifies the size of the buffer passed in <I>lpstrFile</I>.</P>
<P>Similarly, <I>lpstrFileTitle</I> defines a buffer that receives the name of the selected file without the full path name. <I>nMaxFileTitle</I> is passed to specify the size of the buffer pointed to by <I>lpstrFileTitle</I>. <I>lpstrFileTitle</I> can be NULL, in which case <I>nMaxFileTitle</I> is ignored.</P>
<P>The <I>lpstrInitialDir</I> member is a string that specifies the directory whose contents are displayed by the File Open or Save As dialog when it first appears. This member can be NULL.</P>
<P><I>lpstrTitle</I> is the string used as the dialog box caption text. This member can be NULL.</P>
<P><I>nFileOffset</I> specifies a zero-based offset from the beginning of the path to the file name in the string pointed to by <I>lpstrFile</I>. Similarly, <I>nFileExtension</I> is the zero-based offset to the file extension.</P>
<P><I>lpstrDefExt</I> is a string containing the default file extension. This is the extension that is appended to the selected file name if, for example, a user types a file name into the Name field but does not supply an extension. This member can be NULL.</P>
<P>We left out the <I>Flags</I> member. This member is used to specify a set of bit flags that determine various attributes of the File Open dialog box. This member is also used as a return value. <I>GetOpenFileName</I> returns one or more flags to report information about the user’s input.</P>
<P>There are many flags that can be specified in the Flags member of an OPENFILENAME structure. The most common flags and their meanings are given in Table 3.6.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 3.6</B> OPENFILENAME Flag Values
<TR>
<TH WIDTH="40%" ALIGN="LEFT">FLAG
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD VALIGN="TOP">OFN_CREATEPROMPT
<TD>If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file. If the user chooses to create the file, the dialog box closes and the function returns the specified name. Otherwise, the dialog box remains open. This flag is only used with GetSaveFileName.
<TR>
<TD VALIGN="TOP">OFN_EXTENSIONDIFFERENT
<TD>Specifies that the user typed a file-name extension that differs from the extension specified by lpstrDefExt. The function does not use this flag if lpstrDefExt is NULL.
<TR>
<TD VALIGN="TOP">OFN_FILEMUSTEXIST
<TD>Specifies that the user can type only names of existing files in the File Name entry field. If this flag is specified and the user enters an invalid name, the dialog box procedure displays a warning in a message box. If this flag is specified, the OFN_PATHMUSTEXIST flag is also used.
<TR>
<TD>OFN_HIDEREADONLY
<TD>Hides the File Open dialog’s read-only check box.
<TR>
<TD VALIGN="TOP">OFN_NOCHANGEDIR
<TD>Restores the current directory to its original value if the user changed the directory while searching for files.
<TR>
<TD VALIGN="TOP">OFN_NODEREFERENCELINKS
<TD>Directs the dialog box to return the path and file name of the selected shortcut (.LNK) file. If this value is not given, the dialog box returns the path and file name of the file referenced by the shortcut.
<TR>
<TD>OFN_NONETWORKBUTTON
<TD>Hides and disables the Network button.
<TR>
<TD VALIGN="TOP">OFN_OVERWRITEPROMPT
<TD>Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file.
<TR>
<TD VALIGN="TOP">OFN_PATHMUSTEXIST
<TD>Specifies that the user can type only valid paths and file names. If this flag is used and the user types an invalid path and file name in the File Name entry field, the dialog box function displays a warning in a message box.
<TR>
<TD>OFN_SHOWHELP
<TD>Causes the dialog box to display the Help button.
</TABLE>
<P><FONT SIZE="+1"><B><I>An Example</I></B></FONT></P>
<P>All of the foregoing has no doubt caused your eyes to glaze over. Let’s take a look at how the DIALOGS.EXE application creates a File Open dialog to make it all more clear.
</P>
<P>The most important part of creating the File Open dialog is filling an OPENFILENAME structure with the right values. To render the dialog in Figure 3.4, DIALOGS.EXE executes the following code in the function <I>OnFileOpen</I>:</P>
<!-- CODE //-->
<PRE>
void OnFileOpen(HWND hwnd)
{
OPENFILENAME ofn;
TCHAR pszName[256];
DWORD dwSize;
dwSize = sizeof(ofn);
lstrcpy(pszName, TEXT("sample.txt"));
memset(&ofn, 0, dwSize);
ofn.hwndOwner = hwnd;
ofn.lStructSize = dwSize;
ofn.lpstrFilter = TEXT("Text Files (*.txt)\0*.txt\0");
ofn.nFilterIndex = 1;
ofn.lpstrFile = pszName;
ofn.nMaxFile = 256;
ofn.lpstrTitle = TEXT("Open a Text File");
ofn.lpstrInitialDir = TEXT("\\Windows");
ofn.lpstrDefExt = TEXT("txt");
GetOpenFileName(&ofn);
}
</PRE>
<!-- END CODE //-->
<P>The <I>hwnd</I> parameter of <I>OnFileOpen</I> is the main application window. This value is the owner of the File Open dialog. Hence the <I>hwndOwner</I> member of <I>ofn</I> is set to this window.</P>
<P>The filter strings are assigned to <I>ofn.lpstrFilter</I>. The first null-terminated string is used as the contents of the dialog Type: field. The second specifies that the File Open dialog should only display files with the .txt extension.</P>
<P><I>nFilterIndex</I> specifies the 1 -based index of the filter string pair to initially use with the dialog. Setting <I>nFilterIndex</I> to 1 tells the dialog box to use the first filter string pair, the string “Text Files (*.txt)\0*.txt\0.”</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="059-063.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="066-068.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 + -