HOWTO: Use FileOpen Common Dialog w/OFN_ALLOWMULTIPLESELECT

Last reviewed: January 15, 1998
Article ID: Q130761
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows 95

SUMMARY

This article covers the format of file names returned by the FileOpen common dialog with the OFN_ALLOWMULTISELECT style.

The FileOpen common dialog can be used to specify the location (drive and directory) and name of a file or a set of files. One of the flags needed to provide mulitple-file selection from the FileOpen common dialog is the OFN_ALLOWMULTISELECT flag. When this flag is used, and the user makes a valid selection, the file or files chosen by the user are returned in the lpstrFile member of the OPENFILENAME structure. The format of the string returned in the lpstrFile member depends on how many files (single or multiple) the user selected. This article assumes that the OFN_EXPLORER Style is set for the file open dialog.

MORE INFORMATION

If multiple files were selected, the string is of this form:

   Drive: \Directory Name\0FileName 1\0FileName 2\0FileName n\0\0.

The Directory Name is listed first. Then each file that was selected is listed with a terminating NULL Character, except for the last filename, which is terminated with two NULL characters. The two NULL characters signal the end of the string.

If a single file was selected, the string is of this form:

   Drive: \Directory Name\FileName\0\0.

The Directory Name in this case is not terminated by a NULL character, and the file name is terminated with two NULL characters.

Applications must parse the string returned in the lsptrFile member. In doing so, they should make provisions in the parsing code to have a case where the user can make a single selection (even though the OFN_ALLOWMULTISELECT flag is set) or multiple selections.

NOTE: When using OFN_ALLOWMULTISELECT under Windows 95, you need to use the OFN_EXPLORER flag to get the explorer style dialog and NULL terminated strings. If you don't use OFN_EXPLORER with OFN_ALLOWMULTISELECT, you get the old style dialog and space-delimited strings.

Keywords          : UsrCmnDlg kbui
Platform          : WINDOWS


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 15, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.