Reputation: 867
With the code below, the File Save dialog is displayed as expected, with two buttons: Save and Cancel. Clicking Cancel returns with result=IDCANCEL
, but clicking Save or typing Enter does not return from DoModal
, just repaints the Filename window. Is there any reason the Save button should not work?
// Code below is in a message handler of a modeless dialog
CString defaultExt, filter;
defaultExt = "fits";
filter = "FITS image Files (*.fits)|*.fits|All image files (*.img; *.fits)|*.img; *.fits|All Files (*.*)|*.*||";
CFileDialog dlg(FALSE/*save as*/, defaultExt, "GeneratedImage", OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST, filter, this);
int result = (int)dlg.DoModal(); // does not return if Save is clicked
The behavior is the same if the optional argument of CFileDialog
is bVistaStyle=FALSE
.
Visual Studio 2019 v16.7.7, 32-bit debug build, built on and running on 64-bit Windows 7 (same result running on 64-bit Windows 10).
Upvotes: 0
Views: 183
Reputation: 867
Found the problem, sort of. Apparently you cannot save a file to a library.
In Windows 7, navigating to Libraries / Documents in the left pane shows "Documents library, includes 2 locations" in the right pane. Then, clicking Save does nothing. If a different Save as type is selected, I can save.
If I navigate to a simple folder, there is no problem; files can always be saved.
CFileDialog
is behaving as if libraries are read-only, but dependent on the file type selected from the filter AND the extension chosen in the File name box.
Perhaps someone knows where the functionality of CFileDialog
is described in detail.
Upvotes: 0
Reputation: 1
There's also a problem with your filter string. You shouldn't include spaces inside the pattern string.
oldFilter = "FITS image Files (*.fits)|*.fits|All image files (*.img; *.fits)|*.img; *.fits|All Files (*.*)|*.*||";
--- REMOVE THIS SPACE --------------------------------------------------------------^
newFilter = "FITS image Files (*.fits)|*.fits|All image files (*.img; *.fits)|*.img;*.fits|All Files (*.*)|*.*||";
See the lpstrFilter member documentation here: https://learn.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-openfilenamew#members
Upvotes: 0