GetSaveFileName problem: can't get selected filter and put default name

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;
}
 
J

Jim Langston

Leo said:
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;
}

Looks like windows code. Try microsoft.public.vc.language
 
P

Peter Jansson

Leo said:
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

Hello, You may recieve better answers if you ask your question in a
newsgroup dedicated to the platform specific code you are using (windows?).

Regards,
Peter Jansson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top