According to the documentation for the OPENFILENAME structure, the following algorithm is used to select the initial directory:
Windows 7:
- If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.
- Otherwise, if lpstrFile contains a path, that path is the initial directory.
- Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory.
- If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.
- Otherwise, the initial directory is the personal files directory of the current user.
- Otherwise, the initial directory is the Desktop folder.
I'm using the following code to construct a file dialog:
CFileDialog dlgFile(bOpenFileDialog);
dlgFile.m_ofn.lpstrInitialDir = strSourcePath;
dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH);
However, it ALWAYS opens the same default folder in strSourcePath. Does anyone know why? It should only use this directory the first time, and subsequent file opens should remember the last folder (bullet point 1. in the algorithm). I'm using VS2012 on Windows 7.