SpringMVC
asked on
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 :)
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();
ASKER
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_CREAT EPROMPT);, because #define NULL 0, so NULL=0.
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_CREAT
>>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);
do you mean you want the following:
CFileDialog dlgFile(FALSE);
ASKER
In other words, I need OFN_CREATEPROMPT flag
ASKER
No, I mean, I want open file dialog ( so CFileDialog dlgFile(TRUE);), but with OFN_CREATEPROMPT flag.
>>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.
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.
ps. Your original code only opens the CFileDialog once here in a test. Can you post how you are using it
ASKER
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
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
ASKER
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.
ASKER
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.
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.
Please post the complete code you are using.
ASKER
I have created a new MFC project from scratch.
In the function CFileDlgTestApp::OnAppAbou t() I made small changes: I included
CFileDialog dlgFile(TRUE,0,0,OFN_CREAT EPROMPT);
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.
In the function CFileDlgTestApp::OnAppAbou
CFileDialog dlgFile(TRUE,0,0,OFN_CREAT
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();
}
On mine (win 7, 32 bit) just one prompt.
ASKER
If I attach here an exe file, can you test it?
Yes.
ASKER
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
FileDlgTest.exe
Odd - 3 prompt dialogs.
Which version of visual studio are you using?
Which version of visual studio are you using?
ASKER
Compiled with Visual Studio 2008.
1 min - I'll try with Visual Studio 2010.
1 min - I'll try with Visual Studio 2010.
ASKER
with VS2010 - 2 prompt dialogs
ASKER
Tested on 3 machines, Win7, one of them 64bit, on of them 32bit, third - don't know.
My test was with vs2005 - I'll try a vs2010 app here later this evening.
ASKER
Ok.tnx
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.
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.
ASKER
Ok. Anyway, thanks for trying.
PAQ and refund - I could reproduce it here, sounds like a bug.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CFileDialog dlgFile(TRUE);
or
CFileDialog dlgFile(TRUE,NULL, NULL,OFN_CREATEPROMPT);