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
Solved

Get file names from a multiple select open dialog box

Posted on 1998-07-28
6
490 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 50 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 65
sum13 challenge 24 121
Detect file exist or not 3 178
Thin secure Windows 10 5 102
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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