• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3061
  • Last Modified:

CFileDialog on Windows 7 problem.

Hello.
I am facing a weird problem.
If I try to create a file using CFileDialog on Windows 7, the "Save File Dialog", which asks create file or not, appears multiple times ( 2 or 3 ).
For example, use case is: CFileDialog appears, I enter some name and click "Open". If no file exists with such name, the "Save File Dialog" ( with OK and Cancel buttons) asking create file or not will be prompted 2 or 3 times. NB!! This "Save File Dialog" is prompted by CFileDialog inside DoModal function.
The code is simple.
P.S Sorry for my english :)

CFileDialog dlgFile(TRUE,0,0,OFN_CREATEPROMPT);
dlgFile.DoModal();

Open in new window

0
SpringMVC
Asked:
SpringMVC
  • 14
  • 11
1 Solution
 
AndyAinscowCommented:
Does this make any difference ?
CFileDialog dlgFile(TRUE);

or
CFileDialog dlgFile(TRUE,NULL, NULL,OFN_CREATEPROMPT);

0
 
SpringMVCAuthor Commented:
CFileDialog dlgFile(TRUE); - works fine, but it's not behaviour I want, because "Save File Dialog" dialog doesn't appear. I still need it to appear, but only 1 time, not 2 or 3.
CFileDialog dlgFile(TRUE,NULL, NULL,OFN_CREATEPROMPT); - tried, no difference, still 3 times. I think, this is the same, as
CFileDialog dlgFile(TRUE,0,0,OFN_CREATEPROMPT);, because #define NULL 0, so NULL=0.
0
 
AndyAinscowCommented:
>>but it's not behaviour I want, because "Save File Dialog" dialog doesn't appear.

do you mean you want the following:
CFileDialog dlgFile(FALSE);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
SpringMVCAuthor Commented:
In other words, I need OFN_CREATEPROMPT flag
0
 
SpringMVCAuthor Commented:
No, I mean, I want open file dialog ( so CFileDialog dlgFile(TRUE);), but with OFN_CREATEPROMPT flag.
0
 
AndyAinscowCommented:
>>In other words, I need OFN_CREATEPROMPT flag

CFileDialog dlgFile(TRUE);
This will search for a file to OPEN, for reading, why do you need the OFN_CREATEPROMPT for that?

If you want to SAVE to a file then you need to use FALSE as the first parameter in the constructor.
0
 
AndyAinscowCommented:
ps.  Your original code only opens the CFileDialog once here in a test.  Can you post how you are using it
0
 
SpringMVCAuthor Commented:
Hmm.
I don't want to SAVE file, I want to open. But if user enters a name and no file with such name exist, I want OFN_CREATEPROMPT flag, so user will be prompted with dialog ( something like "File does not exist, do you want to create it" ). If user presses No - execution returns to CFileDialog, and this MessageBox disappears - that's correct. But if user presses Yes, in Windows XP - everything works fine, file is NOT created, and DoModal returns IDOK, and this MessageBox disappears. in Windows 7, for some reason, this MessageBox ( again something like "File does not exist, do you want to create it") appears 2 or 3 times, all of them user must press OK button.

temp.jpg
0
 
SpringMVCAuthor Commented:
The problem is, that this dialog must appear only ONE time ( and so it does in Windows XP ), but in Windows 7 - it appears 2 or 3 times.
0
 
SpringMVCAuthor Commented:
P.S My first post is a little bit incorrect, sorry for confusion, I don't want to Save dialog, I want to open it, and if user enters file, which doesn't exist, I just want to prompt a suitable MessageBox ( shown above ). I realize, that CFileDialog ( TRUE ) - won't create file.
0
 
AndyAinscowCommented:
I've just typed a file name directly into the edit box and hit OK (using your original code) - only one prompt.  I'm using windows 7.

Please post the complete code you are using.
0
 
SpringMVCAuthor Commented:
I have created a new MFC project from scratch.
In the function CFileDlgTestApp::OnAppAbout() I made small changes: I included
CFileDialog dlgFile(TRUE,0,0,OFN_CREATEPROMPT);
dlgFile.DoModal();
return;
So then I click "About", this code executes and dialog is prompted multiple times.

Tested on two window 7 machines: first computer prompted 3 times, second prompted 2 times. On WinXP - everything works fine, one prompt.
void CFileDlgTestApp::OnAppAbout()
{
	CFileDialog dlgFile(TRUE,0,0,OFN_CREATEPROMPT);
	dlgFile.DoModal();
	return;

	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

Open in new window

0
 
AndyAinscowCommented:
On mine (win 7, 32 bit) just one prompt.
0
 
SpringMVCAuthor Commented:
If I attach here an exe file, can you test it?
0
 
AndyAinscowCommented:
Yes.
0
 
SpringMVCAuthor Commented:
Here it is. Run it -> Press yellow question mark ( about button ) in the toolbar. CFileDialog(TRUE) will be prompted to you. Enter some file name, which doesn't exist, see how many MessageBox'es will appear.
FileDlgTest.exe
0
 
AndyAinscowCommented:
Odd - 3 prompt dialogs.
Which version of visual studio are you using?
0
 
SpringMVCAuthor Commented:
Compiled with Visual Studio 2008.
1 min - I'll try with Visual Studio 2010.
0
 
SpringMVCAuthor Commented:
with VS2010 -  2 prompt dialogs
0
 
SpringMVCAuthor Commented:
Tested on 3 machines, Win7, one of them 64bit, on of them 32bit, third - don't know.
0
 
AndyAinscowCommented:
My test was with vs2005 - I'll try a vs2010 app here later this evening.
0
 
SpringMVCAuthor Commented:
Ok.tnx
0
 
AndyAinscowCommented:
OK, made a small VS2010 app with your code - 2 prompt dialogs appear (as you get).
I've not found a setting to stop that :-(

This sounds like a bug in VS2010 / Win 7

All I can suggest is that you don't have the OFN_CREATEPROMPT flag and test the file exists yourself when the CFileDialog returns.  If the user then says no you could restart the CFileDialog call.
0
 
SpringMVCAuthor Commented:
Ok. Anyway, thanks for trying.
0
 
AndyAinscowCommented:
PAQ and refund - I could reproduce it here, sounds like a bug.
0
 
ee_autoCommented:
Question PAQ'd and stored in the solution database.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 14
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now