MFC MDI 应用程序中文档的多个视图
我希望 MDI MFC 应用程序中的文档有多个视图。为了做到这一点,我的 App 类的 InitInstance 具有以下代码
m_pMainTemplate = new CMultiDocTemplate(IDR_OpenCVTestTYPE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CImageView));
if (!m_pMainTemplate)
return FALSE;
AddDocTemplate(m_pMainTemplate);
m_pHistTemplate = new CMultiDocTemplate(IDR_OpenCVTestTYPE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CHistogramView));
if (!m_pHistTemplate)
return FALSE;
AddDocTemplate(m_pHistTemplate);
但是当我启动应用程序时,它不断询问用户想要在两个文档中选择哪个文档。当然,这些文件都是同一种文件。有解决这个问题的想法或提示吗?
更新:我通过为第二个视图提供单独的菜单并像这样覆盖 OnFileNew 解决了问题
void CMyApp::OnFileNew()
{
// TODO: Add your command handler code here
m_pMainTemplate->OpenDocumentFile(NULL);
}
I would like to have multiple views for a document in my MDI MFC application. In order to do that, InitInstance of my App class has following code
m_pMainTemplate = new CMultiDocTemplate(IDR_OpenCVTestTYPE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CImageView));
if (!m_pMainTemplate)
return FALSE;
AddDocTemplate(m_pMainTemplate);
m_pHistTemplate = new CMultiDocTemplate(IDR_OpenCVTestTYPE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CHistogramView));
if (!m_pHistTemplate)
return FALSE;
AddDocTemplate(m_pHistTemplate);
But when I start the application, it keeps asking which document among two documents user wants to choose. Of course, those documents are the same kind. Any idea or hint to resolve this problem?
UPDATE: I resolved the problem by having separate menu for the second view and overriding OnFileNew like this
void CMyApp::OnFileNew()
{
// TODO: Add your command handler code here
m_pMainTemplate->OpenDocumentFile(NULL);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要添加第二个模板。
此 Microsoft 知识库文章展示了如何为单个文档创建多个视图。
编辑:一种可能性是在打开必须具有备用视图的子框架之前修改文档模板。
然后,您应该在打开任何类型的子框架之前在模板中设置视图,以确保模板处于每个子框架打开的预期状态。
Don't add a second template.
This Microsoft KB article shows how to create multiple views for a single doc.
EDIT: One possibilty is to modify your document template before opening the child frame that must have the alternate view.
You should then probably set the view in the template before opening any kind of child frame in order to make sure that the template is in the expected state for every child frame opening.