Click to See Complete Forum and Search --> : GetSaveFileName
Mitsukai
April 20th, 2007, 01:11 PM
hi, GetSaveFileName retuns a string without extension.
is there a way i can make it add the extension to the filename?
the filter is ok. i define it like this:
CStringT::ConstDataT ExportFilterList[] = {
S("Scene Editor Object (*.seo)"), S("*.seo"),
S("3D Studio Max Object (*.3ds)"), S("*.3ds"),
S("Blender Object (*.blend)"), S("*.blend"),
S("Milkshape3D Object (*.m3d)"), S("*.m3d"),
S("\0")};
constdatat is either char const* or wchar_t const *
Notsosuperhero
April 20th, 2007, 01:27 PM
I don't think you need the filter as an array, did you try defining the filter like:
char filter* = "File1(.ext1);*.ext1;File2(.ext2);*.ext2;*.*\0";
kkez
April 20th, 2007, 03:37 PM
The lpstrDefExt member of the OPENFILENAME structure gives you the ability to append an extension if the user doesn't type one.
Mitsukai
April 22nd, 2007, 08:53 AM
thanks kkez! i will try.
Mitsukai
April 22nd, 2007, 09:26 AM
this is not what im looking for... it must add the extension from the filter...
Marc G
April 22nd, 2007, 03:40 PM
Can you post your code? How are you calling GetSaveFileName + how are you accessing the selected filename? The lpstrFile member of OPENFILENAME contains drive designator, path, file name, and extension of the selected file.
Mitsukai
April 22nd, 2007, 05:10 PM
const CStringT::ConstDataT ObjectFilterList[] = {
S("Scene Editor Object (*.seo)"), S("*.seo"),
S("3D Studio Max Object (*.3ds)"), S("*.3ds"),
S("Blender Object (*.blend)"), S("*.blend"),
S("Milkshape3D Object (*.m3d)"), S("*.m3d"),
S("\0")};
CStringT SaveFileBox(CStringT::ConstDataT p_Filter = S("All (*.*)\0*.*\0"), CStringT::ConstDataT p_Directory = CApp::Directory(), DWORD p_Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT)
{
CStringT l_FileName(MAX_PATH + 1);
OPENFILENAME l_File = {0};
l_File.lStructSize = sizeof(l_File);
l_File.hwndOwner = Handle();
l_File.lpstrFilter = p_Filter;
l_File.lpstrFile = l_FileName;
l_File.nMaxFile = l_FileName.Capacity();
l_File.lpstrInitialDir = p_Directory;
l_File.Flags = p_Flags;
::GetSaveFileName(&l_File);
l_FileName.SetSize(l_FileName.Capacity());
l_FileName.Depilate(0);
return(l_FileName);
}
void FMainT::MMainT::MFileT::IExportT::OnClick()
{
CStringT l_File = FMain.SaveFileBox(*ObjectFilterList);
// save file
}
i printed l_File and it did NOT have extension
Marc G
April 23rd, 2007, 12:02 PM
The problem is with "l_File.lpstrFilter = p_Filter;". The filter requires embedded \0 characters and that line will truncate the filter at the first \0 character.
To be sure try to replace that line with:
l_File.lpstrFilter = S("Scene Editor Object (*.seo)\0*.seo\0")
S("3D Studio Max Object (*.3ds)\0*.3ds\0")
S("Blender Object (*.blend)\0*.blend\0")
S("Milkshape3D Object (*.m3d)\0*.m3d\0")
S("\0");
Mitsukai
April 23rd, 2007, 01:41 PM
litterals end with NULL character so my code is not wrong.
MrViggy
April 23rd, 2007, 03:13 PM
IIRC, you can only specify one default extension. If you want to use the extension that is selected in the filter, you'll have to do a little work on your own (like a custom save dialog).
Viggy
Marc G
April 23rd, 2007, 03:31 PM
When GetSaveFileName returns it will put the filter that has been selected by the user in OPENFILENAME::nFilterIndex. You can use that index to figure out the selected filter, then check whether the extension is already in the OPENFILENAME::lpstrFile and if not, add the extension yourself.
Mitsukai
April 23rd, 2007, 04:02 PM
thanks, i could use _splitpath to find if there is an extension or not and append the right one from the filter if there is not one, thanks
MrViggy
April 23rd, 2007, 04:03 PM
That's easier then what I suggested. :D
Viggy
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.