L
Leo
I am using OPENFILENAME and GetSaveFileName to let user save a
document out. However, the default name won't show up in the dialog and
the selected filter can't be obtained (always got the default one)
after the dialog is dismissed. Any hint is highly appreciated!
Leo
OPENFILENAME ofn;
TCHAR defDir[MAX_PATH];
TCHAR filePath[MAX_PATH];
TCHAR* title = _T("Save");
ZeroMemory(&ofn, sizeof(OPENFILENAME));
filePath[0] = _T('\0');
DWORD len = MAX_PATH;
DWORD flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = _T("Text file (*.txt)\0*.txt\0Excel file
(*.xls)\0*.xls\0XML file (*.xml)\0*.xml\0\0");
ofn.lpstrFile = filePath;
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = defDir;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = title;
ofn.Flags = flags;
ofn.hwndOwner = hWnd; // make it modal
if :GetSaveFileName(&ofn) && ipChildren)
{
string filter(ofn.lpstrFilter);
string fileName(ofn.lpstrFile);
if (filter == _T("Text file (*.txt)"))
return SaveAsText(fileName, ipChildren);
else if (filte == _T("Excel file (*.xls)"))
return SaveAsExcel(fileName, ipChildren);
else if (filter == _T("XML file (*.xml)"))
return SaveAsXML(fileName, ipChildren);
else
{
Cout << "Wrong input!";
return E_FAIL;
}
document out. However, the default name won't show up in the dialog and
the selected filter can't be obtained (always got the default one)
after the dialog is dismissed. Any hint is highly appreciated!
Leo
OPENFILENAME ofn;
TCHAR defDir[MAX_PATH];
TCHAR filePath[MAX_PATH];
TCHAR* title = _T("Save");
ZeroMemory(&ofn, sizeof(OPENFILENAME));
filePath[0] = _T('\0');
DWORD len = MAX_PATH;
DWORD flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = _T("Text file (*.txt)\0*.txt\0Excel file
(*.xls)\0*.xls\0XML file (*.xml)\0*.xml\0\0");
ofn.lpstrFile = filePath;
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = defDir;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = title;
ofn.Flags = flags;
ofn.hwndOwner = hWnd; // make it modal
if :GetSaveFileName(&ofn) && ipChildren)
{
string filter(ofn.lpstrFilter);
string fileName(ofn.lpstrFile);
if (filter == _T("Text file (*.txt)"))
return SaveAsText(fileName, ipChildren);
else if (filte == _T("Excel file (*.xls)"))
return SaveAsExcel(fileName, ipChildren);
else if (filter == _T("XML file (*.xml)"))
return SaveAsXML(fileName, ipChildren);
else
{
Cout << "Wrong input!";
return E_FAIL;
}