如何在 MFC 中使用文档/视图体系结构
我仍在 MFC 中开发数据采集程序,并且一直在使用文档/视图体系结构。基本上,我希望我的应用程序有几个窗口。一个用于显示从高速摄像机录制的视频,另一个用于显示来自 DAQ 系统的数据,也许另一个具有用于配置摄像机和 DAQ 等的控件。
所以,我确实有很多无模式窗口每个都显示数据的一部分,通常来自不同的来源。现在,在浏览和使用应用程序向导时,我对文档/视图内容感到困惑,即使我可以将其关闭,但从技术上讲它并没有关闭。除此之外,我尝试打开无模式对话框和 FormViews 都没有成功。大多数情况下,我只是不知道如何打开新视图,文档并没有真正的帮助。我已经能够从功能区按钮命令打开模态绘图对话框,并将其标记为成功,但并不完全是我所需要的。
那么,是否有人对将我的应用程序适合文档/视图架构或从另一个应用程序中打开无模式对话框或 FormView 有帮助的见解。我应该说我正在使用 Microsoft Visual Studio 2010,并且我正在使用 MFC 和 C++。
编辑:
所以,我已经使用了 MDI,并且将有一个文档来处理要显示的所有数据。我现在所困扰的是如何创建我想要的多个窗口。我将 CFormView 子类化为文档的图形视图,并且在单击菜单按钮时尝试创建该窗口。我能够使用模态对话框来完成此操作,如下所示:
void CDAQUniversalApp::OnScopebtn()
{
// TODO: Add your command handler code here
CScopeDlg dlg = new CScopeDlg(); //CScopeDlg is Subclass of CDialog
dlg.DoModal();
}
这有效,但不是我想要的,所以我尝试了这个,但它根本不起作用:
m_pScopeTemplate = new CMultiDocTemplate(
IDD_SCOPEFORMVIEW,
RUNTIME_CLASS(CDAQUniversalDoc),
RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CScopeFormView)); //Subclass of CFormView
if (!m_pScopeTemplate)
return FALSE;
void CDAQUniversalApp::OnScopebtn()
{
// TODO: Add your command handler code here
CMDIChildWnd* pFrame = NULL;
pFrame = DYNAMIC_DOWNCAST(CMDIChildWnd, CWnd::GetActiveWindow());
CMDIChildWnd *pScopeFrame = (CMDIChildWnd*)m_pScopeTemplate->CreateNewFrame(pFrame->GetActiveDocument(), NULL);
if (pScopeFrame == NULL)
return;
m_pScopeTemplate->InitialUpdateFrame(pScopeFrame, pFrame->GetActiveDocument(), TRUE);
}
这只会导致未处理的异常。我真的只是用蛮力的方式找到了文档代码的各种基本无用的部分,并将其修改为我认为我需要的内容。
I'm still working on a Data Acquisition program in MFC and am getting stuck working with the Document/View architecture. Basically, I want my application to have a couple windows. One is used to show a video that's recorded from a high speed camera, another has a plot displaying data from the DAQ system, and maybe another has controls for configuring the camera and DAQ, etc.
So, really I have a lot of modeless windows each showing a portion of the data, usually from a different source. Now, going through and using the App Wizard I get confused with the Doc/View stuff, and even though I can turn it off, it isn't technically off. Now that aside, I've tried opening modeless Dialogs and FormViews all to no success. Mostly I just can't figure out how to open the new View, the documentation isn't really helpful. I've been able to open a Modal plotting dialog from a Ribbon Button command and I mark that as a success, but not exactly what I need.
So, does anyone have helpful insight on fitting my application to the Doc/View architecture or opening a modeless dialog or FormView from within another application. I should say I'm using Microsoft Visual Studio 2010 and I'm using MFC and C++.
EDIT:
So, I've gone with MDI and will have one document that handles all the data to be shown. What I am stuck on now is how to create the multiple windows I want. I sublcassed CFormView to be the graph View of the document, and I am trying to create that window when I click a menu button. I was able to do it with a modal Dialog, like this:
void CDAQUniversalApp::OnScopebtn()
{
// TODO: Add your command handler code here
CScopeDlg dlg = new CScopeDlg(); //CScopeDlg is Subclass of CDialog
dlg.DoModal();
}
That worked, but not what I want, so I tried this, and it didn't work at all:
m_pScopeTemplate = new CMultiDocTemplate(
IDD_SCOPEFORMVIEW,
RUNTIME_CLASS(CDAQUniversalDoc),
RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CScopeFormView)); //Subclass of CFormView
if (!m_pScopeTemplate)
return FALSE;
void CDAQUniversalApp::OnScopebtn()
{
// TODO: Add your command handler code here
CMDIChildWnd* pFrame = NULL;
pFrame = DYNAMIC_DOWNCAST(CMDIChildWnd, CWnd::GetActiveWindow());
CMDIChildWnd *pScopeFrame = (CMDIChildWnd*)m_pScopeTemplate->CreateNewFrame(pFrame->GetActiveDocument(), NULL);
if (pScopeFrame == NULL)
return;
m_pScopeTemplate->InitialUpdateFrame(pScopeFrame, pFrame->GetActiveDocument(), TRUE);
}
This just causes an unhandled exception. I really just bruteforced my way to that point finding various largely unhelpful sections of documentation code and modifying it to what I think I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的不同窗口(用于视频显示、数据显示和配置)实际上是单个文档的所有视图(不同的视图类),该文档管理数据(假设 DAQ 处理视频数据?)。
我建议您将应用程序打包到 MDI 应用程序中,从而拥有一个主窗口,并将所有这些不同的视图作为子窗口。因此,单个文档(甚至 MDI 中的多个文档)有多个视图。
如果您的应用程序不适合经典的文档/视图体系结构(例如 Word),MFC 可能会很痛苦,但我认为这将是使您的应用程序适合此框架的最佳方式。
Your different windows (for video display, data display and configuration) are actually all views (different view classes) for a single document, which manages the data (assuming the DAQ works on the video data?).
I suggest you pack your application into an MDI app, thus having a main window, with all those different views as subwindows. So you have multiple views for a single document (or even multiple documents in MDI).
MFC can be a pain, if your application does not fit the classical document/view architecture (like Word for example), but I think this would be the best way to fit your application into this framework.