Re: CFileDialog
David Ching wrote:
"jc" <jc@discussions.microsoft.com> wrote in message
news:A7F3BCCB-370A-4572-81A1-8633BADA4080@microsoft.com...
How do I set the default path for a CFileDialog.
It seems like the path that is displayed is random.
CFileDialog dlg (TRUE); // MFC File Open dialog
dlg.m_ofn.lpstrInitialDir = strDesiredDir;
I just went through this. Here's a snippet:
CStringW szFile;
CFileDialog fdlg(TRUE);
// 2048 is the max buffer size allowed
fdlg.m_ofn.lpstrFile = szFile.GetBuffer(2048);
fdlg.m_ofn.nMaxFile = 2048;
fdlg.m_ofn.lpstrFilter = _T("Ext\0*.ext\0All\0*.*\0");
fdlg.m_ofn.lpstrTitle = _T("Select File(s) To Add ...");
fdlg.m_ofn.lpstrInitialDir = NULL;
fdlg.m_ofn.Flags |= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
OFN_ALLOWMULTISELECT | OFN_EXPLORER;
if (fdlg.DoModal()==IDOK)
{
CStringW filename;
POSITION pos;
// retrieve all filenames selected by user
pos = fdlg.GetStartPosition();
while (pos)
{
filename = fdlg.GetNextPathName(pos);
.
.
.
}
}
// buffer is automatically released when it goes out
// out of scope - but ReleaseBuffer is called here
// explicitly out of habit ...
szFile.ReleaseBuffer();