Multiple Views, And A Single Document
Spencer Jones -- Spencer@azure.com Monday, September 30, 1996 Environment: VC++ 4.2 and Windows NT 4.0 I have been working from an example in the MSDN called TANGRAM.EXE to write an application that has multiple views attached to a single document. This example seems strange because it creates each of the views as a CMultiDocTemplate. What I really want to do is create multiple views fully independent of the MDI. This would seem an obvious thing to do, as the CDocument can point at multiple views. So am I missing something. The closest I can get is to use splitter windows. But I would rather have independent view windows that relate to a single document application. The problems I find with the TANGRAM.EXE example is it always gives a warning about not creating a dialog and the views appear to be documents and take the window name of the document as the view name. I guess what I really want to know is how to create a set of views as windows all belonging to the same document. I don't want to swap the views into the document ( I can do that ) I want to display them ( and cascade or tile them ) at the same time. Any offers? Spencer Jones ( http://www.azure.com/~spencer/ ) Chief Software Developer Azure Limited
Frederic Steppe -- FredericS@msn.com Wednesday, October 02, 1996 [Mini-digest: 3 responses] >Environment: VC++ 4.2 and Windows NT 4.0 > >I have been working from an example in the MSDN called TANGRAM.EXE to >write an application that has multiple views attached to a single >document. This example seems strange because it creates each of the >views as a CMultiDocTemplate. What I really want to do is create >multiple views fully independent of the MDI. > >This would seem an obvious thing to do, as the CDocument can point at >multiple views. So am I missing something. The closest I can get is to >use splitter windows. But I would rather have independent view windows >that relate to a single document application. You may try looking at CMDIFrameWnd::OnWindowNew in MFC sources. Here is how I would do the job (based on MSVC 4.1) : BOOL CMyMDIFrameWnd::CreateNewView(CDocument *pExistingDoc, CDocTemplate *pTemplate /*= NULL*/, CMDIChildWnd* pModel /*= NULL*/) { if(pTemplate == NULL) pTemplate = pExistingDoc->GetDocTemplate(); // Will create same type of view if no template is given CFrameWnd* pFrame = pTemplate->CreateNewFrame(pDocument, pModel); if (pFrame == NULL) { TRACE0("Warning: failed to create new frame.\n"); return FALSE; // command failed } pTemplate->InitialUpdateFrame(pFrame, pDocument); return TRUE; } Frederic Steppe (frederics@msn.com) -----From: "Cunningham Graham, IK 23"Take a look at an example vswap from microsofts softlib. Although this only deals with swapping views there is enough info here to show you how to have multiple views attached to one document. The class you need to look at is CCreateContext as this needs to be setup to point to the document before creating the view. A good place to do this if you have a fixed set of views is in CMainFrame::OnCreateClient. regards Graham Cunningham 00 41 31 338 0633 -----From: ganeshs@nationwide.com This is the "recommended" method of having multiple views on a single document, where the views are of different classes, and have their own frames... > This would seem an obvious thing to do, as the CDocument can point at > multiple views. So am I missing something. The closest I can get is to > use splitter windows. But I would rather have independent view windows > that relate to a single document application. > > The problems I find with the TANGRAM.EXE example is it always gives a > warning about not creating a dialog and the views appear to be documents > and take the window name of the document as the view name. > > I guess what I really want to know is how to create a set of views as > windows all belonging to the same document. I don't want to swap the > views into the document ( I can do that ) I want to display them ( and > cascade or tile them ) at the same time. Well, if the views are of the same class, it becomes simpler. Create a MDI app with a single CMultiDocTemplate, modify File-Open etc, to close the current document before opening another one. The Window menu would already have the functionality for the other features you desire... / ___| / ___| __ _ _ __ ___ ___| | I do not speak for \___ \ | | _ / _` | '_ \ / _ \/ __| '_ \ Tata Unisys or ___) | | |_| | (_| | | | | __/\__ \ | | |Nationwide Ins. |____(_) \____|\__,_|_| |_|\___||___/_| |_|------------------
Roger Onslow/Newcastle/Computer Systems Australia/ Thursday, October 03, 1996 [Mini-digest: 2 responses] >I have been working from an example in the MSDN called TANGRAM.EXE to >write an application that has multiple views attached to a single >document. This example seems strange because it creates each of the >views as a CMultiDocTemplate. What I really want to do is create >multiple views fully independent of the MDI. Well, it is not strange .. just that you want to do something different :-) >This would seem an obvious thing to do, as the CDocument can point at >multiple views. So am I missing something. The closest I can get is to >use splitter windows. But I would rather have independent view windows >that relate to a single document application. So you want single document, multiple views. Basically SDI on the document side of things and MDI on the view side. >The problems I find with the TANGRAM.EXE example is it always gives a >warning about not creating a dialog and the views appear to be documents >and take the window name of the document as the view name. Bad example to start with then -- of is it related to what you have done to it to get the framework you want? >I guess what I really want to know is how to create a set of views as >windows all belonging to the same document. I don't want to swap the >views into the document ( I can do that ) I want to display them ( and >cascade or tile them ) at the same time. Are the views to be of the same class? Or are they different classes of view? These are two different "kettles of fish", and require different techniques. >Any offers? I think this was discuessed in some MSJ articles. If you subscribe to MSDN, you should be able to search for some hlpe on this. If I get some spare time (don't get much of that lately) then I may have a look for you and let you know. Roger Onslow -----From: "Schiebel, Edward N."I've done this. It was a while ago, so I can't be sure this solution is complete. Each of my view classes had a static member functions for creating views: CMainFrame* CTableView::CreateFramedView(CWinApp& theApp, CMyDoc* pDoc) { CSingleDocTemplate* pTableTemplate = new CSingleDocTemplate(resourceID, RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CMainFrame), RUNTIME_CLASS(CTableView)); theApp.AddDocTemplate(pTableTemplate); CMainFrame* pTableWnd = 0; if((pTableWnd = (CMainFrame*) pTableTemplate->CreateNewFrame(pDoc, NULL)) == NULL) { TRACE0("Failed creating the expansion window"); return NULL; } pTableTemplate->InitialUpdateFrame(pTableWnd, pDoc); return pTableWnd; } Ed Schiebel AT&T Network and Computing Services e.n.schiebel@att.com
John Bundgaard -- johnb@image.dk Friday, October 04, 1996 Hi Spencer. You can create a new view using the following metod: // // Create new frame window for the view. // NOTE: CMyFrame is deriven from CMDIChildWnd // CMyFrame* pFrame = new CMyFrame; // // Set the title of the view. The variable m_strViewtitle should be public // CString that you add to the CMyFrame class. // pFrame->m_strViewTitle = "Title of your view"; // // Get pointer to existing document. // CDocument* pMyDoc = GetDocument(); CCreateContext cc; cc.m_pNewViewClass = RUNTIME_CLASS(CMyView); cc.m_pCurrentDoc = pMyDoc; cc.m_pNewDocTemplate = NULL; cc.m_pLastView = NULL; cc.m_pCurrentFrame = NULL; pFrame->Create(NULL,pMyDoc->GetTitle(), WS_CHILD | WS_OVERLAPPEDWINDOW, CMDIChildWnd::rectDefault, NULL, &cc); pFrame->InitialUpdateFrame(pMyDoc,TRUE); I order to get the correct title on the frame window, then you have to override OnUpdateFrameTitle in you CMyFrame class, and add the m_strViewTitle variable. In the CMyFrame header: public: virtual void OnUpdateFrameTitle(BOOL); CString m_strViewTitle; In the CMyFrame cpp file: void CStdChildFrame::OnUpdateFrameTitle(BOOL bAdd) { GetMDIFrame()->OnUpdateFrameTitle(bAdd); SetWindowText(m_strViewTitle); } That's it! John Bundgaard johnb@image.dk ---------- > From: Spencer Jones> To: 'MFC List' > Subject: Multiple Views, And A Single Document > Date: 30. september 1996 15:49 > > Environment: VC++ 4.2 and Windows NT 4.0 > > I have been working from an example in the MSDN called TANGRAM.EXE to > write an application that has multiple views attached to a single > document. This example seems strange because it creates each of the > views as a CMultiDocTemplate. What I really want to do is create > multiple views fully independent of the MDI. > > This would seem an obvious thing to do, as the CDocument can point at > multiple views. So am I missing something. The closest I can get is to > use splitter windows. But I would rather have independent view windows > that relate to a single document application. > > The problems I find with the TANGRAM.EXE example is it always gives a > warning about not creating a dialog and the views appear to be documents > and take the window name of the document as the view name. > > I guess what I really want to know is how to create a set of views as > windows all belonging to the same document. I don't want to swap the > views into the document ( I can do that ) I want to display them ( and > cascade or tile them ) at the same time. > > Any offers? > > > Spencer Jones ( http://www.azure.com/~spencer/ ) > Chief Software Developer > Azure Limited
| Вернуться в корень Архива |