CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    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.
    mpliam

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  3. #3
    Join Date
    May 2002
    Posts
    1,798

    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.
    Last edited by Mike Pliam; November 1st, 2013 at 12:08 PM.
    mpliam

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: How to get the Encoder drop down in a File Save dialog ?

    Quote Originally Posted by Mike Pliam View Post
    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

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  6. #6
    Join Date
    May 2002
    Posts
    1,798

    Re: How to get the Encoder drop down in a File Save dialog ?

    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.
    mpliam

  7. #7
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: How to get the Encoder drop down in a File Save dialog ?

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to get the Encoder drop down in a File Save dialog ?

    Quote Originally Posted by Mike Pliam View Post
    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)
    Victor Nijegorodov

  9. #9
    Join Date
    May 2002
    Posts
    1,798

    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.
    mpliam

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to get the Encoder drop down in a File Save dialog ?

    Quote Originally Posted by Mike Pliam View Post
    ... 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 View Post
    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)
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured