4

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.

Nate
  • 259
  • 1
  • 4
  • 12

1 Answers1

3

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.

Christian Rau
  • 45,360
  • 10
  • 108
  • 185
  • Well, how it works is that there are at most three different sources of information, Camera is firewire (C++ lib), DAQ is a pcicard (C lib), and a serial port, all different information that get acquired at the same time. But MDI does sound like it makes sense. I assume a Document would have the data acquired from all sources and each View would show each specific data. I haven't found a good source on how this interaction works or how to write it, do you have insight or a good sample/tutorial/book on how to do that? – Nate May 08 '11 at 22:34
  • 1
    @Nate It's been a long time since I worked with MFC (using Qt now). I learned with the book "Programming Windows with MFC", which is THE standard ressource, but its quite heavy-weight and not easy to find/pay (I was lucky to get it at a reasonable cost). I'm not that fit in MFC anymore (and I don't want to be, as it can really be a pain, compared to cleanly designed and flexible APIs like Qt) – Christian Rau May 08 '11 at 23:46
  • Thanks, I'll be sure to look at that one. I've been doing MFC just because it comes with Visual Studio, I think the libraries I'm using are designed for VC++, but then again I'm not familiar with C++ at all. – Nate May 09 '11 at 00:15
  • @Nate, How do the video window, the plot and the controls relate to each other? Is it one video and several plots or one video and one plot? With Doc/View, we assume that there is one document holding data and several views into that data. As an example, we can have a document describing a movie and several views such as a trailer window, an IMDB window, a wiki entry and so on. But you will have to get familiar with C++ before trying MFC. – Agnel Kurian May 09 '11 at 16:01
  • @Agnel, Ideally, the document would control the DAQ software and camera, so it would have the data to be plotted and the video file. The video window would shows the video, A video controls window would adjust the playback and set parameters, Another window would plot the data in the document, and another view would control what channels to acquire data from, scan rate etc. I've gotten the hang of C++, know C well enough, and am familiar with OOP from Python, so I'm beginning to piece the structure together. I've been able to refine my inquiry to a specific question now. – Nate May 09 '11 at 16:27