|
-
April 20th, 2007, 12:11 PM
#1
GetSaveFileName
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:
Code:
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 *
-
April 20th, 2007, 12:27 PM
#2
Re: GetSaveFileName
I don't think you need the filter as an array, did you try defining the filter like:
Code:
char filter* = "File1(.ext1);*.ext1;File2(.ext2);*.ext2;*.*\0";
-
April 20th, 2007, 02:37 PM
#3
Re: GetSaveFileName
The lpstrDefExt member of the OPENFILENAME structure gives you the ability to append an extension if the user doesn't type one.
-
April 22nd, 2007, 07:53 AM
#4
-
April 22nd, 2007, 08:26 AM
#5
Re: GetSaveFileName
this is not what im looking for... it must add the extension from the filter...
-
April 22nd, 2007, 02:40 PM
#6
Re: GetSaveFileName
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.
-
April 22nd, 2007, 04:10 PM
#7
Re: GetSaveFileName
Code:
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
Last edited by Mitsukai; April 22nd, 2007 at 04:13 PM.
-
April 23rd, 2007, 11:02 AM
#8
Re: GetSaveFileName
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:
Code:
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");
-
April 23rd, 2007, 12:41 PM
#9
Re: GetSaveFileName
litterals end with NULL character so my code is not wrong.
-
April 23rd, 2007, 02:13 PM
#10
Re: GetSaveFileName
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
-
April 23rd, 2007, 02:31 PM
#11
Re: GetSaveFileName
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.
-
April 23rd, 2007, 03:02 PM
#12
Re: GetSaveFileName
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
-
April 23rd, 2007, 03:03 PM
#13
Re: GetSaveFileName
That's easier then what I suggested. 
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|