Question : How can I get CFileDialog to not change the initial directory?


Our application has a very large number of instances in which a CFileDialog is opened. We've added one in which we want to keep a separate default directory. i.e so in general the CFileDialog keeps it's initial directory from the last time the user accessed a file. However in this instance we want to default to a different directory without changing the previously remembered directory used by the rest of the application.

It's the last part that I can't get to work. I thought that it should be easy to use the OFN_NOCHANGEDIR flag with the CFileDialog, but this doesn't seem to do anything.

I have also tried saving the current directory before using the file dialog and then restoring it using these methods:

CString currentDir;
::GetCurrentDirectory(MAX_PATH, currentDir.GetBuffer(MAX_PATH));
currentDir.ReleaseBuffer();

...do file access

::SetCurrentDirectory(currentDir);

While currentDir appears to be obtained correctly, SetCurrentDirectory doesn't appear to influence the next time a file dialog is opened.

Is the "current directory" actually the right thing to set? If so at what point does CFileDialog usually set it?

I'd really like some soultion that doesn't mean going through the whole code base and changing every existing file dialog.




Answer : How can I get CFileDialog to not change the initial directory?

That's now you say you knew. :)

There is only one place where such things are stored - the registry. You can try to debug you program - you will see the MFC source code (CWinApp, CDocManager) and this place in the registry. I think, it will be HKLM/Software/Provider/Application/something.

I think there is a way to override CDocManager methods:
http://www.codeguru.com/cpp/w-d/dislog/commondialogs/print.php/c1967




Random Solutions  
 
programming4us programming4us