[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 780
  • Last Modified:

Diff between CreateNewFrame() and LoadFrame() for new views?

I have a document that contains data gathered from remote testers. It's not a file that the user can open. I have a view showing the data in text format in a grid. I want another view summarizing the data in a bar chart. Currently I am opening the new view's window by creating a doc template in InitInstance() like so:

               // this done by class wizard:
      CMultiDocTemplate* pDocTemplate;
      pDocTemplate = new CMultiDocTemplate(
            IDR_HOSTTYPE,
            RUNTIME_CLASS(CHostDoc),
            RUNTIME_CLASS(CChildFrame),      // this frame has 'X' disabled, and other customizations
            RUNTIME_CLASS(CHostView));
      AddDocTemplate(pDocTemplate);

               // my new template
      m_pSummaryViewTemplate = new CMultiDocTemplate(
            IDR_OVEN_SUMMARY,               // refers only to a string resource, not a menu or icon
            RUNTIME_CLASS(CHostDoc),
            RUNTIME_CLASS(CMDIChildWnd),
            RUNTIME_CLASS(CSummaryView));
      AddDocTemplate(m_pSummaryViewTemplate);

Then I open the frame from a menu handler with CDocTemplate::CreateNewFrame per the CHKBOOK sample or Blaszczak pg 196. This is working with some caveats, see below.

I understand I could also creat a new view/frame using LoadFrame() and a CCreateContext object. What's the difference?  Which is the better route? A timer running in the main view should do an UpdateAllViews() when it trips.

The caveats mentioned above are 1) My summary frame title is the same as my CHostView frame, not the one I thought would be referenced by my IDR_OVEN_SUMMARY string, and 2) I want both child windows to have the same menu options, and MFC is greying out the ones it thinks my summary shouldn't have. The VIEWEX sample seemed to do what I was doing, but its menus are the same for both views. I do NOT want to maintain 2 menus like they did in CHKBOOK.

Thanks for your help on this,
NC
0
nchenkin
Asked:
nchenkin
  • 5
  • 3
  • 2
1 Solution
 
psdavisCommented:
-- You are probably storing the template m_pSummaryViewTemplate in Iyour CWinApp, so wherever you want to open the view, do a OpenDocumentFile to get your document object.

CMyWinApp* pApp = (CMyWinApp*) AfxGetApp( );
CDocument* pDoc = pApp->m_pSummaryViewTemplate->OpenDocumentFile( NULL );      

-- This way your frame title is changed with

pDoc->SetTitle( "Your Title" );

-- To get your menu options, the way I do it is to either have two menus, one for IDR_OVEN_SUMMARY and one for IDR_HOSTTYPE.  Therefore, the menus will be highlighted, enabled, or checked per your current class.


0
 
psdavisCommented:
Oops, missed the comment about not wanting two menus.  OK, shot in the dark... how about a dummy menu for IDR_OVEN_SUMMARY and once it is created, do a SetMenu function on the view?
0
 
nchenkinAuthor Commented:
Hello psdavis,

Your OpenDocumentFile(NULL) is *yet another approach* and it seems to be working although I'd like to understand how calling it with NULL opened the correct document. But maybe I should just have faith and leave it at that! My window title now also is correct per my IDR_OVEN_SUMMARY resource string, so we've made progress.

But creating a dummy menu doesn't happen. If I just do an "Insert Menu" in my resource list, teh compiler deletes this if I haven't actually edited anything in the menu.

Next step?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nchenkinAuthor Commented:
Actually, after playing with OpenDocumentFile(), I decided that I don't want to open another document, I just want a new view of an already open document.

This brings me back, I think,  to my original question of CreateNewFrame() vs LoadFrame() / CCreateContext.

Thanks,
NC
0
 
psdavisCommented:
The OpenDocumentFile does perform the CreateNewFrame.  It's more of a wrapper than anything.  The NULL is for passing a file name to open.  The CMultiDocTemplate stores the name of the CDocument so it knows the document when it does the OnNewDocument.

I'll take a separate look at having two documents with only one menu in a bit.
0
 
psdavisCommented:
The OpenDocumentFile does perform the CreateNewFrame.  It's more of a wrapper than anything.  The NULL is for passing a file name to open.  The CMultiDocTemplate stores the name of the CDocument so it knows the document when it does the OnNewDocument.

I'll take a separate look at having two documents with only one menu in a bit.
0
 
psdavisCommented:
Not that I'm trying to avoid your question, but if you have an existing document, and you want to add a new view to that document, then the CDocument::AddView( CView* ) function is probably more your style.
0
 
piano_boxerCommented:
Here is a function that will open a new view attached to the current document.
USAGE: OpenNewView(pExistingDoc, RUNTIME_CLASS(CMySuperView), "My Syper View");

void OpenNewView(CDocument* pDoc, CRuntimeClass* pClass, LPCSTR lpszTitle)
{
    ASSERT_VALID(pDoc);
    ASSERT_VALID(pClass);

    // Create the frame
    CMDIChildWnd* pFrame = new CMDIChildWnd;
    pf->m_strViewTypeName = lpszTitle;
    pf->m_strDocTitle = pDoc->GetTitle();

    CCreateContext cc;
    cc.m_pNewViewClass = pClass;
    cc.m_pCurrentDoc = pDoc;
    cc.m_pNewDocTemplate = NULL;
    cc.m_pLastView = NULL;
    cc.m_pCurrentFrame = NULL;

    // Create frame and view    
    pFrame->Create(NULL,pDoc->GetTitle(), WS_CHILD | WS_OVERLAPPEDWINDOW, CMDIChildWnd::rectDefault, NULL, &cc);
    pFrame->InitialUpdateFrame(pDoc,TRUE);
}
0
 
nchenkinAuthor Commented:
Hello piano_boxer,

I think that's what I was looking for!

There were compile errors on ASSERT_VALID(pClass) and the undeclared pf and its members, but once I nuked them it was OK.

CDoc::UpdateAllViews() is working so the new frames are attached to the right doc. I still need to figure out how to keep my menu items enabled when this frame has focus, but I should be able to handle that.

Thanks,
NC
0
 
piano_boxerCommented:
Ok, sorry for my mistakes.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now