Solved

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

Posted on 1998-07-10
10
706 Views
Last Modified: 2013-11-19
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
Comment
Question by:nchenkin
  • 5
  • 3
  • 2
10 Comments
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
-- 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
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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
 

Author Comment

by:nchenkin
Comment Utility
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
 

Author Comment

by:nchenkin
Comment Utility
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
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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
 
LVL 4

Accepted Solution

by:
piano_boxer earned 100 total points
Comment Utility
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
 

Author Comment

by:nchenkin
Comment Utility
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
 
LVL 4

Expert Comment

by:piano_boxer
Comment Utility
Ok, sorry for my mistakes.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 153
Detect CR LF to each line 12 134
has77  challenge 9 66
wordcount challenge 11 71
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now