Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

GetOpenFileName( )

Posted on 2000-04-21
3
Medium Priority
?
612 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

649 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