?
Solved

GetOpenFileName( )

Posted on 2000-04-21
3
Medium Priority
?
595 Views
Last Modified: 2013-12-03
Im using GetOpenFileName() to pull in one or multiple files from a user.  The problem is how do I go about parsing the "strFile" field in the OPENFILENAME structure, since it contains many embedded strings?

For example if the user choose "hello.txt and "goodbye.txt" in the "c:\words" folder the string would look like this...

"c:\words\hello.txt"goodbye.txt""

if the user just chose "hello.txt" in the "c:\words" folder the string would look like this...

"c:\words\hello.txt"

Whats a good algrorithm to use to end up with this...

MyString1 = "c:\words\hello.txt"
MyString2 = "c:\words\goodbye.txt"


Thanks,
-Dan
0
Comment
Question by:dmaroff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 300 total points
ID: 2739651
<<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. >>

So,

1) Use OFN_EXPLORER along with OFN_ALLOWMULTISELECT

2)
OPENFILENAME ofn;
GetOpenFileName(...)


//Detect if a single file was selected:
int len=strlen(ofn.lpstrFile);
if(ofn.lpstrFile[len+1]==0) {
   // Single file selected,
   // ofn.lpstrFile contains the full path and file name.
   printf("Single file=%s",ofn.lpstrFile);
}
else {

// ofn.lpstrFile contains directory
printf("Directory=%s",ofn.lpstrFile);

ofn.lpstrFile+=len+1;
// Enumerate all file names.
while(ofn.lpstrFile[0]) {
   // ofn.lpstrFile contains the file name
   printf("Next file=%s",ofn.lpstrFile);
   // Find next name
   len=strlen(ofn.lpstrFile);
   ofn.lpstrFile+=len+1;

}


0
 

Author Comment

by:dmaroff
ID: 2741240
Ok, Im going to try it out and let you know.

Thanks,
-Dan
0
 

Author Comment

by:dmaroff
ID: 2743954
Your code worked beautifully.

Thanks a lot,

-Dan
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question