Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get file names from a multiple select open dialog box

Posted on 1998-07-28
6
Medium Priority
?
521 Views
Last Modified: 2013-11-20
I have a multiple select open dialog box, and I would like to get file names from the File Name edit box.  I use the following code, but what I got from GetNextPathName( position ) is an empty string...


POSITION position = GetStartPosition( );
CString pFileName = GetNextPathName( position );
while ( pFileName != "" )
{
    ...
    pFileName = GetNextPathName( position );
}

Is there any wrong with this code?  I have set the OFN_ALLOWMULTISELECT flag.  Thanks.
0
Comment
Question by:syu
[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
  • 3
  • 2
6 Comments
 

Author Comment

by:syu
ID: 1319846
Edited text of question
0
 

Expert Comment

by:Moshe072898
ID: 1319847
Here is my code that works. ChooseFile is the name of the dialog.
Be sure that your buffer (m_ofn.lpstrFile ) is initialized properly (see below) :

      char *szChosenFiles = new char[150*MAX_PATH];
      if(!szChosenFiles)
            return;

      strcpy(szChosenFiles,_T(""));
      ChooseFile.m_ofn.lpstrFile = szChosenFiles;
      ChooseFile.m_ofn.nMaxFile = 150*MAX_PATH;
      if(ChooseFile.DoModal() == IDOK){
                              POSITION  Position =  ChooseFile.GetStartPosition();
               while(Position != NULL){
                  strFileName = ChooseFile.GetNextPathName(Position);
                                 // do what you want
                }

0
 

Author Comment

by:syu
ID: 1319848
I forgot to mention that I put my code on the OnFileNameChange function because I need file names when the Open dialog box is still active.  I setup the lpstrFile and nMaxFile before calling the DoModal( ), but it still doesn't work.  
After GetNextPathName( position ), position is always 0x00000000.
Is there any reason why it doesn't work?
Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:chensu
ID: 1319849
CFileDialog::GetNextPathName can only be used after DoModal().
0
 

Author Comment

by:syu
ID: 1319850
I figured that out.  But is there any way I can get the file names in the class?  I got the control of the File Name edit box and got the file names in one CString.  Well, is there any way I can get each file name out from that CString?  I am thinking to get the control of the List View to get the current selected file name.
Thanks.

0
 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 1319851
>is there any way I can get each file name out from that CString?
Yes, look into the source code of CFileDialog::GetStartPosition() and CFileDialog::GetNextPathName in AFXDLGS.INL and DLGFILE.CPP. It is quite independent from the other parts. You can use the code with slight modification.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

610 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