I have a requirement to present an open file dialog to a user and prevent them from changing the directory from the default. Supposedly, this can be done by setting the Flags field in the OFN_STRUCT to OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST + OFN_NOCHANGEDIR when calling GetOpenFileNameA, yet I’m not getting any joy. The dialog box appears with the right title, filter list, and default directory, but the Flags don’t seem to take. There is no error on returning control, and the file name is placed in the lpstrFile field as expected. Part of the debugging involved setting the Flags to other values such as OFN_HIDEREADONLY, and none of those work either, except for the OFN_ENABLEHOOK and OFN_ALLOWMULTISELECT flags.
Does anyone have any ideas on how to fix this, or if there’s another option? I don’t want to have to write a procedure to emulate an open file dialog.
OFN_NOCHANGEDIR 0x00000008
Restores the current directory to its original value if the user changed the directory while searching for files.
This flag is ineffective for GetOpenFileName.
#1 the purpose is to “Restore the Current Directory” i.e. when it returns the Current Directory (i.e. Clarion PATH()) is what it was before the call. Clarion’s FileDialog() has this flag as FILE:KeepDir.
So this is not what you want … but IMO you do want the flag ON. It is usually going to be very very bad for your EXE to suddenly the Current Directory … unless your file names contain the path or you set Prop Data Path.
#2 oddly it says it does Not apply to GetOpenFileName() … which I wonder about. Maybe they mean it does allow changing it while it is open, which could cause problems for a multi-threaded program.
A workaround is to save the LongPath() before the FileDialog() then SetPath(Saved) after. This a good thing to do in Reports because if the Driver is set to write to a file that can change Current Directory.
One way is when FileDialog() returns check the Path of LongPath(FilePicked) not equal LongPath() then show a Message() that file MUST come from the Folder LongPath().
Another way is to make your own File Picker window. It’s not that hard using DIRECTORY() and a LIST.
I’m certain I wasn’t going to be able to do it using GetOpenFileNameA, so I looked at what you had done, and the wndExplorer demo is a great place to start with a window that looks similar. So that’s the solution. Thanks, Jeff!