Solved

CFileDialog on Windows 7 problem.

Posted on 2010-09-09
27
2,878 Views
Last Modified: 2013-11-20
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
Comment
Question by:SpringMVC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 11
27 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33634663
Does this make any difference ?
CFileDialog dlgFile(TRUE);

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

0
 

Author Comment

by:SpringMVC
ID: 33634741
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33634793
>>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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SpringMVC
ID: 33634794
In other words, I need OFN_CREATEPROMPT flag
0
 

Author Comment

by:SpringMVC
ID: 33634800
No, I mean, I want open file dialog ( so CFileDialog dlgFile(TRUE);), but with OFN_CREATEPROMPT flag.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33634804
>>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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33634858
ps.  Your original code only opens the CFileDialog once here in a test.  Can you post how you are using it
0
 

Author Comment

by:SpringMVC
ID: 33634876
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
 

Author Comment

by:SpringMVC
ID: 33634887
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
 

Author Comment

by:SpringMVC
ID: 33634908
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33634943
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
 

Author Comment

by:SpringMVC
ID: 33635182
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33637028
On mine (win 7, 32 bit) just one prompt.
0
 

Author Comment

by:SpringMVC
ID: 33637119
If I attach here an exe file, can you test it?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33637380
Yes.
0
 

Author Comment

by:SpringMVC
ID: 33637443
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33637543
Odd - 3 prompt dialogs.
Which version of visual studio are you using?
0
 

Author Comment

by:SpringMVC
ID: 33637562
Compiled with Visual Studio 2008.
1 min - I'll try with Visual Studio 2010.
0
 

Author Comment

by:SpringMVC
ID: 33637619
with VS2010 -  2 prompt dialogs
0
 

Author Comment

by:SpringMVC
ID: 33637633
Tested on 3 machines, Win7, one of them 64bit, on of them 32bit, third - don't know.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33637686
My test was with vs2005 - I'll try a vs2010 app here later this evening.
0
 

Author Comment

by:SpringMVC
ID: 33637970
Ok.tnx
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33639350
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
 

Author Comment

by:SpringMVC
ID: 33640230
Ok. Anyway, thanks for trying.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34118328
PAQ and refund - I could reproduce it here, sounds like a bug.
0
 

Accepted Solution

by:
ee_auto earned 0 total points
ID: 34153391
Question PAQ'd and stored in the solution database.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

726 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