Solved

Get file names from a multiple select open dialog box

Posted on 1998-07-28
6
464 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now