Solved

Get file names from a multiple select open dialog box

Posted on 1998-07-28
6
485 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 125
cat dog challenge 18 124
List out all word 7 296
dog bark java program 15 98
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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