How to get the Encoder drop down in a File Save dialog ?
I need to have a user option to save a file as either UTF-8 or UTF-16, such as NotePad does. But I cannot figure out how to get the CFileDialog to display the Encoder drop down selector. Does anyone know how to do this. I am aware the since VISTA there is another API that one can use, but that API is not compatible with pre-VISTA OS 's. Thanks.
Re: How to get the Encoder drop down in a File Save dialog ?
For the OpenFile dialog. This is done by a custom template and setting the OFN_ENABLETEMPLATE flag.
Marius Bancila has a blog entry on this: http://mariusbancila.ro/blog/tag/preview/
For the newer "Common Item Dialog" (Vista and up). See http://msdn.microsoft.com/en-us/libr.../bb776913.aspx
This has explanations of how to customize the dialog.
Re: How to get the Encoder drop down in a File Save dialog ?
I need something that works for pre-VISTA, VISTA, and post-VISTA as well. I cannot get it to work after reviewing the Marius Bancila's blog and the M$ websites. Really need a coded example. For one thing, there is no explanation of where the 'dialog template' comes from, whether or not they pre-exist somewhere, can be downloaded, or need to be created from scratch (and if so, how?). Where does Marius pull out "DIALOG_PREVIEW"? I can find no reference to it anywhere. Furthermore, while Marius' code compiles on my Win2k / VS 2010 machine, it doesn't work properly.
Here's a smattering of my code:
Code:
wchar_t szFilters[]= _T("Database Template Files (*.tpl)|*.tpl|Comma Separated Values File (*.csv)|*.csv|Xml Database Table Files (*.xml)|*.xml|All Files (*.*)|*.*||");
//CFileDialog fileDlg (FALSE, _T("tpl"), _T("*.tpl"), OFN_HIDEREADONLY, szFilters, this);
CFileDialog fileDlg(FALSE, NULL, NULL, OFN_HIDEREADONLY,szFilters, this);
//fileDlg.m_ofn.Flags |= OFN_ENABLETEMPLATE;
//fileDlg.m_ofn.hInstance = AfxGetInstanceHandle();
//fileDlg.m_ofn.lpTemplateName = _T("DIALOG_PREVIEW");
The lines that are commented out, if left in, result in failure of the dialog to open altogether (Win2k) but doesn't crash or produce any error message. On Win7 (64-bit) machine, it compiles and runs with those lines but produces behaviour unlike that predicted by Marius.
I'm confused.
Re: How to get the Encoder drop down in a File Save dialog ?
Quote:
Originally Posted by
Mike Pliam
For one thing, there is no explanation of where the 'dialog template' comes from, whether or not they pre-exist somewhere, can be downloaded, or need to be created from scratch (and if so, how?).
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
and the templates are part of the Platform SDK. These .dlg files exist in the SDK's include directory.
Regards,
Paul McKenzie
Re: How to get the Encoder drop down in a File Save dialog ?
the 'old' open file dialog sample from marius will work in later versions too.
the blog entry is quite complete and has a full working sample. You make your own container template and compile/link it in the resources of your exe.
If you have a VS Express edition, then you'll have to find an external resource editor since there isn't one included in the VSExpress IDE.
You can't do this with a runtime-created dialog. It is possible if you make a dialog template at runtime, but that's a whole story entirely that would take lots of explaining how to do.
Re: How to get the Encoder drop down in a File Save dialog ?
Quote:
You make your own container template and compile/link it in the resources of your exe.
Exactly how do you do this? Do you mean create a new dialog resource in the resource editor and populate it with all the controls that you need, then somehow link it to the VS 2010 MFC app? Or is there some other method you are referring to. I like the way everyone throws around this 'Well, just create your own dialog template...' and fails to go on to explain what they mean by this. Even the google sites that I've visited have failed to illuminate this puzzle for me. I understand how one sets up the flags in the CFileDialog initialization so that a dialog template can be used. But from there on I'm lost. And Marius' oft quoted blog does not refer to an Encoding Dropdown box anywhere that I can see.
Re: How to get the Encoder drop down in a File Save dialog ?
Re: How to get the Encoder drop down in a File Save dialog ?
Quote:
Originally Posted by
Mike Pliam
Exactly how do you do this? Do you mean create a new dialog resource in the resource editor and populate it with all the controls that you need, then somehow link it to the VS 2010 MFC app? Or is there some other method you are referring to. I like the way everyone throws around this 'Well, just create your own dialog template...' and fails to go on to explain what they mean by this. Even the google sites that I've visited have failed to illuminate this puzzle for me. I understand how one sets up the flags in the CFileDialog initialization so that a dialog template can be used. But from there on I'm lost. And Marius' oft quoted blog does not refer to an Encoding Dropdown box anywhere that I can see.
Mike, I suggest you to git rid of the vista style dialog box and only use the "old Explorer-style" one.
In such a case you would need to customize only the "old Explorer-style" dialog. See:
http://msdn.microsoft.com/en-us/magazine/cc301466.aspx
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx (note stc32 control ID)
http://support.microsoft.com/kb/195034/en-us
Note that you will need to derive your own class from CFileDialog to handle CDN_INITDONE message.
When overriding its ctor just call the base class ctor passing in zero and FALSE as the very last parameters (to use the default size of OPENFILENAME struct and to avoid Vista style dialog)
Re: How to get the Encoder drop down in a File Save dialog ?
Thanks. As I suspected, rolling your own custom dialog template is no small matter. If you doubt me, take a look at the CCustomFileDialog class in the MSDN sample found at http://support.microsoft.com/kb/195034/en-us. Furthermore, this best of the sample projects that I could find (thanks Victor) doesn't work!! It compiles and runs on Win 7 (64-bit) (sans hcrtf) but selecting 'Custom Template' from the View menu and attempting to use it results in 'Attempted an unsupported operation' message box with no debug output or call stack information generated. Weird !
I think I'll give this quest up for now and wait until someone posts some modern workable project.
Re: How to get the Encoder drop down in a File Save dialog ?
Quote:
Originally Posted by
Mike Pliam
... It compiles and runs on Win 7 (64-bit) (sans hcrtf) but selecting 'Custom Template' from the View menu and attempting to use it results in 'Attempted an unsupported operation' message box with no debug output or call stack information generated. Weird !
I think I'll give this quest up for now and wait until someone posts some modern workable project.
Mike, did you do the following:
Quote:
Originally Posted by
VictorN
When overriding its ctor just call the base class ctor passing in zero and FALSE as the very last parameters (to use the default size of OPENFILENAME struct and to avoid Vista style dialog)