Visual C++ 中 MFC 中文件 open/save 中的可选文件格式
Selectable file formats at file open/save in MFC in Visual C++
我的英语不是很好,抱歉。
我正在使用带有 MFC 的 Visual C++ 2019 Community。
在CFileDialog
class,我希望选择文件编码:UTF-16 (little/big endian), UTF-8, ANSI, etc, at saving, with or without签名(2 个或字节,表示编码的符号,位于文件开头)。这应该联系到 open/save 按钮。在 CFileDialog
的文档中,我只能添加单独的按钮,而不是像 Visual Studio、LibreOffice 等中那样扩展 open/save 按钮。我该怎么做?我是 MFC 和桌面程序的初学者,但不是 C++ 的初学者。谢谢。
在对您的问题的评论中,您声明:
Yes, I know. But there is no place to write this. Handler of Open menu is built-in part of MFC. At the source code, CFileDialog
is not happen. I added handler OnFileOpen()
. This has not paramters, empty at now, and the open menu item manages well. So, I do not know to where I type OFN_ALLOWMULTISELCT
.
如果您查看 Technical Note 22,它会提到:
ID_FILE_OPEN
Opens an existing document.
Note
You must connect this to your CWinApp
-derived class's message map to
enable this functionality.
CWinApp::OnFileOpen
has a very simple implementation of calling
CWinApp::DoPromptFileName
followed by CWinApp::OpenDocumentFile
with
the file or path name of the file to open. The CWinApp
implementation
routine DoPromptFileName
brings up the standard FileOpen
dialog and
fills it with the file extensions obtained from the current document
templates.
One common customization of ID_FILE_OPEN
is to customize the FileOpen
dialog or add additional file filters. The recommended way to
customize this is to replace the default implementation with your own
FileOpen
dialog, and call CWinApp::OpenDocumentFile
with the
document's file or path name. There is no need to call the base class.
如您所见,它指出:
The CWinApp
implementation
routine DoPromptFileName
brings up the standard FileOpen
dialog and
fills it with the file extensions obtained from the current document
templates.
但是 DoPromptFileName
似乎是一个未记录的函数。您可以:
- 调试到 MFC 源代码以查看它的作用并在您自己的应用程序中覆盖它class,
- 继续推出您自己的
CWinApp::OnFileOpen
覆盖,它使用您自己的 CFileDialog
。
我建议您还阅读 CFileDialog
构造函数文档,因为它会帮助您进行基本的自定义。但是,在我看来你需要按照@sergiol 在评论中所说的那样做并显示你自己的 CFileDialog
(使用前面描述的任何一种方法)并添加你自己的组合和你的编码选项。然后相应处理。
请注意,我没有那种级别的定制经验,但它应该可以帮助您。
我的英语不是很好,抱歉。
我正在使用带有 MFC 的 Visual C++ 2019 Community。
在CFileDialog
class,我希望选择文件编码:UTF-16 (little/big endian), UTF-8, ANSI, etc, at saving, with or without签名(2 个或字节,表示编码的符号,位于文件开头)。这应该联系到 open/save 按钮。在 CFileDialog
的文档中,我只能添加单独的按钮,而不是像 Visual Studio、LibreOffice 等中那样扩展 open/save 按钮。我该怎么做?我是 MFC 和桌面程序的初学者,但不是 C++ 的初学者。谢谢。
在对您的问题的评论中,您声明:
Yes, I know. But there is no place to write this. Handler of Open menu is built-in part of MFC. At the source code,
CFileDialog
is not happen. I added handlerOnFileOpen()
. This has not paramters, empty at now, and the open menu item manages well. So, I do not know to where I typeOFN_ALLOWMULTISELCT
.
如果您查看 Technical Note 22,它会提到:
ID_FILE_OPEN
Opens an existing document.Note
You must connect this to your
CWinApp
-derived class's message map to enable this functionality.
CWinApp::OnFileOpen
has a very simple implementation of callingCWinApp::DoPromptFileName
followed byCWinApp::OpenDocumentFile
with the file or path name of the file to open. TheCWinApp
implementation routineDoPromptFileName
brings up the standardFileOpen
dialog and fills it with the file extensions obtained from the current document templates.One common customization of
ID_FILE_OPEN
is to customize theFileOpen
dialog or add additional file filters. The recommended way to customize this is to replace the default implementation with your ownFileOpen
dialog, and callCWinApp::OpenDocumentFile
with the document's file or path name. There is no need to call the base class.
如您所见,它指出:
The
CWinApp
implementation routineDoPromptFileName
brings up the standardFileOpen
dialog and fills it with the file extensions obtained from the current document templates.
但是 DoPromptFileName
似乎是一个未记录的函数。您可以:
- 调试到 MFC 源代码以查看它的作用并在您自己的应用程序中覆盖它class,
- 继续推出您自己的
CWinApp::OnFileOpen
覆盖,它使用您自己的CFileDialog
。
我建议您还阅读 CFileDialog
构造函数文档,因为它会帮助您进行基本的自定义。但是,在我看来你需要按照@sergiol 在评论中所说的那样做并显示你自己的 CFileDialog
(使用前面描述的任何一种方法)并添加你自己的组合和你的编码选项。然后相应处理。
请注意,我没有那种级别的定制经验,但它应该可以帮助您。