Re: GetOpenFilename()
- From: "William DePalo [MVP VC++]" <willd.no.spam@xxxxxxxx>
- Date: Wed, 15 Feb 2006 16:58:32 -0500
"DR" <dr1234@xxxxxxxxx> wrote in message
news:e8JPYPnMGHA.3064@xxxxxxxxxxxxxxxxxxxxxxx
What is the recommended way to check if multiple files were selected or
only one after a GetOpenFilename() call? Is there sample code? Basically I
want to get a list of the selected files (with full pathes).
Have you seen this in the help entry for the function?
<quote>
OFN_ALLOWMULTISELECT
Specifies that the File Name list box allows multiple selections. If you
also set the OFN_EXPLORER flag, the dialog box uses the Explorer-style user
interface; otherwise, it uses the old-style user interface.
If the user selects more than one file, the lpstrFile buffer returns the
path to the current directory followed by the file names of the selected
files. The nFileOffset member is the offset, in bytes or characters, to the
first file name, and the nFileExtension member is not used. For
Explorer-style dialog boxes, the directory and file name strings are NULL
separated, with an extra NULL character after the last file name. This
format enables the Explorer-style dialog boxes to return long file names
that include spaces. For old-style dialog boxes, the directory and file name
strings are separated by spaces and the function uses short file names for
file names with spaces. You can use the FindFirstFile function to convert
between long and short file names.
If you specify a custom template for an old-style dialog box, the definition
of the File Name list box must contain the LBS_EXTENDEDSEL value
</quote>
If the function succeeds you always have at least one complete path to a
file.
So, here is one way. You determine the first path's length and then add that
advance a pointer that many characters.That brings you to the trailing null
byte. You advance the pointer one character more. If the pointer references
the terminator (0) you are done. If note you advance one character more.
To build a list you could pass through the string once to get the number of
files, then create an array of that many pointers, and pass through the
string a second time inserting the pointers to the first characters of each
of the strings you find into the array.
Regards,
Will
.
- Follow-Ups:
- Re: GetOpenFilename()
- From: DR
- Re: GetOpenFilename()
- References:
- GetOpenFilename()
- From: DR
- GetOpenFilename()
- Prev by Date: GetOpenFilename()
- Next by Date: Re: GetOpenFilename()
- Previous by thread: GetOpenFilename()
- Next by thread: Re: GetOpenFilename()
- Index(es):
Relevant Pages
|