I use the MFC interface IFileOpenDialog for selecting the source data file. Obviously, dialog is open in last used directory (folder).
I want to open the dialog in folder, the user send to function (the path in the parameter lsCurFolder). I have not find how to do it.
inline bool OpenFile(LPTSTR& pszFilePath, const FileType fTyp = MajCut, LPCTSTR lsCurFolder) {
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog* pFileDlg = NULL;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileDlg));
if (!SetTyp(fTyp, pFileDlg, L"Vyhledej soubor pro načtení"))
{
pFileDlg->Release();
return false;
}
FILEOPENDIALOGOPTIONS opt;
pFileDlg->GetOptions(&opt);
if (pFileDlg->SetOptions(opt | FOS_STRICTFILETYPES) != S_OK)
{
pFileDlg->Release();
return false;
}
if (SUCCEEDED(hr))
{
// Show the Open dialog box.
hr = pFileDlg->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem* pItem;
hr = pFileDlg->GetResult(&pItem);
if (SUCCEEDED(hr))
{
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); //Volající musí zrušit volání voláním CoTaskMemFree
pItem->Release();
}
}
pFileDlg->Release();
}
CoUninitialize();
}
return SUCCEEDED(hr);
}
Per Controlling the Default Folder:
So, for example: