Opening multiple views automatically
Paul E. Rosen -- prosen@fte.com Friday, November 01, 1996 Environment: VC++4.2flat, Win95 I have created an MDI app with multiple views attached to the same document. When the user opens a document, I want to put up the same views in the same places on the screen that the user had when he closed the document. I tried opening up an extra view in my OnOpenDocument(), but I got a strange child window that didn't repaint. Also, the framework wants to open up a view automatically before OnOpenDocument() gets control. Can I suppress that? Where is the correct place to open up views? Here is how I'm setting up my Doc/View structure: (Code is heavily edited for brevity) class CMyApp : public CWinApp { public: CMultiDocTemplate* m_pSummary; CMultiDocTemplate* m_pLog; }; BOOL CMyApp::InitInstance() { m_pLog = new CMultiDocTemplate( IDR_LOGTYPE, RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CLogView)); AddDocTemplate(m_pLog); m_pSummary = new CMultiDocTemplate(IDR_SUMMARYTYPE, RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CSummaryView)); } // This is called in response to a button press, it works fine. void CMyDoc::OnShowsummary() { CMyApp* pApp = (CMyApp*)AfxGetApp(); CFrameWnd* pFrameWnd = pApp->m_pSummary->CreateNewFrame(this,NULL); if (!pFrameWnd) return; pApp->m_pSummary->InitialUpdateFrame(pFrameWnd, this); } // This is how I would like to open a document, but // 1) a default view that I don't want is created // 2) the views that I specified are not appearing correctly. BOOL CMyDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; CMyApp* pApp = (CMyApp*)AfxGetApp(); CFrameWnd* pFrameWnd = NULL; CMultiDocTemplate* pTemp = NULL; pTemp = pApp->m_pSummary; pFrameWnd = pTemp->CreateNewFrame(this,NULL); pTemp->InitialUpdateFrame(pFrameWnd, this); return TRUE; } Thanks Paul Rosen, Frontline Test Equipment, Inc. Internet: prosen@fte.com, http://www.fte.com, ftp.fte.com Voice: 804-984-4500, Fax: 804-984-4505, BBS: 804-984-4503 Real Mail: PO Box 7507, Charlottesville, VA 22906-7507, USA Location: 2114 Angus Road, Suite 228, Charlottesville, VA 22901
Si Cruse -- scruse@csfp.co.uk Monday, November 04, 1996 Paul E. Rosen wrote: > > Environment: VC++4.2flat, Win95 > > I have created an MDI app with multiple views attached to the same document. > When the user opens a document, I want to put up the same views in the same > places on the screen that the user had when he closed the document. I tried > opening up an extra view in my OnOpenDocument(), but I got a strange child > window that didn't repaint. Also, the framework wants to open up a view > automatically before OnOpenDocument() gets control. Can I suppress that? Where > is the correct place to open up views? > > Here is how I'm setting up my Doc/View structure: (Code is heavily edited for > brevity) > > class CMyApp : public CWinApp > { > public: > CMultiDocTemplate* m_pSummary; > CMultiDocTemplate* m_pLog; > }; > > BOOL CMyApp::InitInstance() > { > m_pLog = new CMultiDocTemplate( > IDR_LOGTYPE, > RUNTIME_CLASS(CMyDoc), > RUNTIME_CLASS(CChildFrame), > RUNTIME_CLASS(CLogView)); > AddDocTemplate(m_pLog); > > m_pSummary = new CMultiDocTemplate(IDR_SUMMARYTYPE, > RUNTIME_CLASS(CMyDoc), > RUNTIME_CLASS(CChildFrame), > RUNTIME_CLASS(CSummaryView)); > > } I assume you AddDocTemplate(m_pSummary) ? Of course you do... > // This is called in response to a button press, it works fine. > void CMyDoc::OnShowsummary() > { > CMyApp* pApp = (CMyApp*)AfxGetApp(); > CFrameWnd* pFrameWnd = pApp->m_pSummary->CreateNewFrame(this,NULL); > if (!pFrameWnd) > return; > > pApp->m_pSummary->InitialUpdateFrame(pFrameWnd, this); > } > > // This is how I would like to open a document, but > // 1) a default view that I don't want is created Don't call OnFileNew from your CMyApp::InitInstance > // 2) the views that I specified are not appearing correctly. > BOOL CMyDoc::OnOpenDocument(LPCTSTR lpszPathName) > { > if (!CDocument::OnOpenDocument(lpszPathName)) > return FALSE; > > CMyApp* pApp = (CMyApp*)AfxGetApp(); > CFrameWnd* pFrameWnd = NULL; > CMultiDocTemplate* pTemp = NULL; > pTemp = pApp->m_pSummary; > pFrameWnd = pTemp->CreateNewFrame(this,NULL); > pTemp->InitialUpdateFrame(pFrameWnd, this); > > return TRUE; > } > Why is your document creating views? This seems bad OO design to me! You should have a helper function in your app do the document creation & view switching... (Look at the top of your MyApp.cpp and you'll see OnFileNew & OnFileOpen reflected to CWinApp. Why not override these yourself to stitch the required views to a new document?!) -- ...A closed mouth gathers no foot... _____________________________________________________________ Si Cruse Front Office IT Development, Credit Suisse Financial Products 1 Cabot Square, London E14 4QJ Phone: +44 171 516 2948 Fax: +44 171 516 2688 mailto:scruse@csfp.co.uk http://www.cruse.demon.co.uk
Jim Lawson Williams -- jimlw@mail.ccur.com.au Wednesday, November 06, 1996 [Mini-digest: 2 responses] G'day! On Fri, 1 Nov 1996 11:17:00 prosen@fte.com (Paul E. Rosen) wrote: >I want to put up the same views in the same places on the screen that >the user had when he closed the document. You could put the data in the Registry, an .INI file, or actually store it in the document. I believe all 3 have been discussed over the last 3 or 4 months. If you want to be thorough, you should also retain the mainframe state. See Kruglinski's "Inside Visual C++" for his "Persistent Frame" example. >I got a strange child window that didn't repaint. Perhaps due to the lack of a "CDocument::UpdateAllViews()"? >the framework wants to open up a view automatically before OnOpenDocument() >gets control. Can I suppress that? See below. Also discussed recently. >Where is the correct place to open up views? Application and personal-preference dependent, according to when you want a new view and how the action is initiated. I guess that comment isn't too helpful, but you give no clues. Consider, however, the "New Window" mainframe menu-choice: decide if/how you intend to support that. Check the last few months of the archives for "multiple views". Regards, Jim LW BOOL CFredApp::InitInstance() {CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) { //No new doc. here... cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; pMainFrame = new CMainFrame ((CWinApp*) this,/*Doc. Handling Enabled =*/FALSE); } else { //handle the doc. we were supplied: pMainFrame = new CMainFrame ((CWinApp*) this,/*Doc. Handling Enabled =*/TRUE); } m_pMainWnd = pMainFrame; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; } -----From: "Alexander Grigoriev" Paul, I think, the best place to create additional child frames is in OnInitialUpdate of the main view class (created by doc manager).
| Вернуться в корень Архива |