syu
asked on
Get file names from a multiple select open dialog box
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.
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.
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.GetStartPositio n();
while(Position != NULL){
strFileName = ChooseFile.GetNextPathName (Position) ;
// do what you want
}
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
ChooseFile.m_ofn.nMaxFile = 150*MAX_PATH;
if(ChooseFile.DoModal() == IDOK){
POSITION Position = ChooseFile.GetStartPositio
while(Position != NULL){
strFileName = ChooseFile.GetNextPathName
// do what you want
}
ASKER
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.
After GetNextPathName( position ), position is always 0x00000000.
Is there any reason why it doesn't work?
Thanks.
CFileDialog::GetNextPathNa me can only be used after DoModal().
ASKER
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.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER