473,545 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening multiple files in an MFC dialog application

79 New Member
I want to be able to select mutliple files from a standard File Open dialog box, and be able to open all those files simultaneously.

How can this be done? Is there a specific flag that you can use in the CFileDialog class constructor?

This is how I've been doing it, but just for one file:

CFileDialog FileDlg(TRUE, _T("*.txt"), NULL, 0, _T("Text Files (*.txt)|*.txt|" ));

Thanks
Jul 10 '07 #1
3 4434
weaknessforcats
9,208 Recognized Expert Moderator Expert
Read this. Especially, how to use OFN_ALLOWMULTIS ELECT.
Jul 11 '07 #2
ahammad
79 New Member
Thanks, I finally got it to work, but now there is another problem.

If I select a small number of files, it works. If I select a larger number of files (+5), it exits the loop as if I had clicked "cancel" in the dialog box.

Expand|Select|Wrap|Line Numbers
  1. CFileDialog cfileDlg( TRUE, _T("*.cpf"), NULL, OFN_ALLOWMULTISELECT, _T("CPF Files (*.cpf)|*.cpf|" ));
  2.  
  3.     CString csFileDlgTitle;
  4.  
  5.     cfileDlg.m_ofn.lpstrTitle = csFileDlgTitle;
  6.  
  7.     //int nRet = cfileDlg.DoModal( );
  8.     //ASSERT( ( nRet != IDOK ) || ( nRet != IDCANCEL ) );
  9.  
  10.     if (cfileDlg.DoModal() != IDOK) {
  11.         return;    //EXITS HERE IF I SELECT A LOT OF FILES, REGARDLESS OF WHAT I CLICK//
  12.     }
  13.  
  14.     POSITION pos ( cfileDlg.GetStartPosition() );
  15.  
  16.     while( pos )
  17.     {
  18.         CString csFileName(  cfileDlg.GetNextPathName( pos ) );
  19.  
  20.         FileOpenInput(csFileName);
The code that was commented out worked before, I took it out for other reasons.

I marked where the function terminates. That if statement is meant to be entered if the user clicks cancel in the File Open dialog box. What is the reason for this?

Thanks
Jul 11 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
So if DoModal() does not return IDOK, then what does it return??

I would have expected code like:
Expand|Select|Wrap|Line Numbers
  1. if (cfileDlg.DoModal() == IDCANCEL)
  2. {
  3.         switch(CommDlgExtendedError())
  4.         {
  5.               case: CDERR_FINDRESFAILURE
  6.                        // etc...
  7.                       break;
  8. //etc...
  9. }
  10. //Then you get here on IDOK
  11.  
Jul 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2363
by: yanivoliver | last post by:
Hey, I'm currently trying to find a way to open a dialog box that will allow me to select more than one file at a time, so if I want to upload select all the files in a directory, I won't have to have the number of dialog boxes as files in the directory. I was thinking of using a ActiveX control, but I don't want to make the sure download...
2
2833
by: Johann Blake | last post by:
I can hardly believe I'm the first one to report this, but having gone through the newsgroup, it appears that way. I would like to open a solution in the VS.NET IDE that consists of multiple DLLs and a test application (an .EXE). The .EXE is my startup application. All the DLLs are shared components. This means that they contain a key and...
0
1904
by: vinX | last post by:
Ok, i am making a file renaming utility, you can add filesize (in MB o KB), filepath, creation date and/or time, a counter, parent folder, th original name etc... I put the program in the (registry: *.*\shell\myprogram\command(valu of the comand key is "...\myprogram.exe" "%1") context menu, so tha when you select multiple files, the paths...
2
2076
by: Matt Hamilton | last post by:
I have an application page with a datagrid with a checkbox on each row. The user should check the rows they want to modify and then click a button. When the button is clicked, I have a Click handler that builds a url and then registers a startup script to open a modal dialog window. With XP SP2 installed the pop-up blocker stops the windows...
5
3665
by: Stanav | last post by:
Hello all, Thanks in advance for any replies... Now, my question is: Is it possible to do a multiple files download for a single response event on an aspx page? If there is, please give me some directions/sample code or anything. On my web application, I have a CheckBoxList that shows all the files. The user will check (select) the files...
16
2187
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
4
2159
by: Pieter | last post by:
Hi, From my VB.NET 2005 application I need to be able to open Files an Directory's with their default application: - A word-doc must open in word - A excell-document in Excel etc - in case it's a folder it must open the Folder No problem there, but when I want to open a file without extension, that hasn't offcourse a default...
10
3663
by: kimiraikkonen | last post by:
Hi, I have an app which has a listbox and when i double click an associated fileS, i want their paths to be added into listbox in my application. This code works good when i try to open a "single" file with my app which works to get commandline arguments to get file paths: Dim cla As String() = Environment.GetCommandLineArgs() If...
1
2427
navanova
by: navanova | last post by:
Greetings, I have a problem of opening ms word and excel files on my computer. The files are there for a long time. I use to open and modify them. Suddenly, when i try to open the word files, a dialog box appears that says "There was an error opening the file". when i try to open the excel files, a dialog box appears that says "File format not...
0
7405
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7659
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7428
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7760
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3455
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.