Solved

CFileDialog on Windows 7 problem.

Posted on 2010-09-09
27
2,768 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
  • 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now