I am trying to extract the initial directory so that the user can start from the folder that they chose last time. I use a CFileDialog to open the file and in Win98 it typically starts in "My Documents". If the user navigates somewhere else, then this folder is remembered for the duration of the session. I want to remember this so that I can set it at the start of the next session. I thought that in the WM_CLOSE of the CMainFrame class I could put the following:
CString sFinalDir = fd.m_ofn.lpstrInitialDir;
theApp.WriteProfileString(SETTINGS_KEY, INITIALDIR_KEY, sFinalDir);
I could then do the following in the InitInstance of my app:
// find initial directory, if any
m_sInitialDir = GetProfileString(SETTINGS_KEY, INITIALDIR_KEY);
and stuff this into the m_ofn struct so that subsequent File Opens would start at the previous folder.
Unfortunately the m_ofn contains a null for the lpstrInitialDir when I do the WM_CLOSE. How can I get at the internal folder that CFileDialog is holding so that I can start there next time. Once I have this how can I ensure that this folder is the place to start next time. I was going to create a CFileDialog and then set the m_ofn.lpstrInitialDir member to the last directory that I can recover from the registry.