A CFileDialog Question - selecting multiple files
-
I have created and displayed a file dialog to select multiple files. But when i select more then four files and hit enter or prell the ok button, the selection is erased and all that is left is the text in the entry box under the listbox. When trying to recover the files selected, the dialog box sends back nothing. can some one help me pleeeeese:confused:
-
I have created and displayed a file dialog to select multiple files. But when i select more then four files and hit enter or prell the ok button, the selection is erased and all that is left is the text in the entry box under the listbox. When trying to recover the files selected, the dialog box sends back nothing. can some one help me pleeeeese:confused:
What flags do you pass to the constructor? I usually use OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT Maybe you can post some code? Cheers,
/FredrikDo you Sonork? I do! 100.11430:PhatBoy
-
I have created and displayed a file dialog to select multiple files. But when i select more then four files and hit enter or prell the ok button, the selection is erased and all that is left is the text in the entry box under the listbox. When trying to recover the files selected, the dialog box sends back nothing. can some one help me pleeeeese:confused:
You have to allocate your own buffer for the returned files. The default buffer is too small.
TCHAR MyBuffer[1024];
CFileDialog fdlg;
fdlg.m_ofn.lpstrFile = MyBuffer;
fdlg.m_ofn.nMaxFile = 1024;Look up OPENFILENAME in MSDN. --- Sonork 100.11743 Chicken Little It may be that your sole purpose in life is simply to serve as a warning to others.
-
You have to allocate your own buffer for the returned files. The default buffer is too small.
TCHAR MyBuffer[1024];
CFileDialog fdlg;
fdlg.m_ofn.lpstrFile = MyBuffer;
fdlg.m_ofn.nMaxFile = 1024;Look up OPENFILENAME in MSDN. --- Sonork 100.11743 Chicken Little It may be that your sole purpose in life is simply to serve as a warning to others.
IMHO, it is easier to use the functions of CFileDialog to retrieve the files. Then you don't have to worry about buffer sizes. CString strFileName(""); POSITION pos; CStringList* strlistFileNames; CFileDialog FileDlg( true, // File Open dialog. "*", // Default file name extension. NULL, // No initial filename. OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, m_strNameMask + " (" + m_strSuffixMask + ")" + "|" + m_strSuffixMask + "|All Files (*.*)|*.*||" ); FileDlg.m_ofn.lpstrTitle = "Select files"; pos = FileDlg.GetStartPosition(); while (pos != NULL) { strlistFileNames->AddTail(FileDlg.GetNextPathName(pos)); } Cheers,
/FredrikDo you Sonork? I do! 100.11430:PhatBoy
-
IMHO, it is easier to use the functions of CFileDialog to retrieve the files. Then you don't have to worry about buffer sizes. CString strFileName(""); POSITION pos; CStringList* strlistFileNames; CFileDialog FileDlg( true, // File Open dialog. "*", // Default file name extension. NULL, // No initial filename. OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, m_strNameMask + " (" + m_strSuffixMask + ")" + "|" + m_strSuffixMask + "|All Files (*.*)|*.*||" ); FileDlg.m_ofn.lpstrTitle = "Select files"; pos = FileDlg.GetStartPosition(); while (pos != NULL) { strlistFileNames->AddTail(FileDlg.GetNextPathName(pos)); } Cheers,
/FredrikDo you Sonork? I do! 100.11430:PhatBoy
From MSDN <quote> To allow the user to select multiple files, set the OFN_ALLOWMULTISELECT flag before calling DoModal. You need to supply your own filename buffer to accommodate the returned list of multiple filenames. Do this by replacing m_ofn.lpstrFile with a pointer to a buffer you have allocated, after constructing the CFileDialog, but before calling DoModal. Additionally, you must set m_ofn.nMaxFile with the number of characters in the buffer pointed to by m_ofn.lpstrFile. </quote> --- Sonork 100.11743 Chicken Little It may be that your sole purpose in life is simply to serve as a warning to others.