文書番号: 99562
最終更新日: 2003/07/21
CView* m_pOldView; CView* m_pNewView; CView* SwitchView(CView* pNewView);
... CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView(); m_pOldView = pActiveView; m_pNewView = (CView*) new CNewView; CDocument* pCurrentDoc = ((CFrameWnd*) m_pMainWnd)->GetActiveDocument(); // Initialize a CCreateContext to point to the active document. // With this context, the new view is added to the document // when the view is created in CView::OnCreate(). CCreateContext newContext; newContext.m_pNewViewClass = NULL; newContext.m_pNewDocTemplate = NULL; newContext.m_pLastView = NULL; newContext.m_pCurrentFrame = NULL; newContext.m_pCurrentDoc = pCurrentDoc; // The ID of the initial active view is AFX_IDW_PANE_FIRST. // Incrementing this value by one for additional views works // in the standard document/view case but the technique cannot // be extended for the CSplitterWnd case. UINT viewID = AFX_IDW_PANE_FIRST + 1; CRect rect(0, 0, 0, 0); // gets resized later // Create the new view. In this example, the view persists for // the life of the application. The application automatically // deletes the view when the application is closed. m_pNewView->Create(NULL, "AnyWindowName", WS_CHILD, rect, m_pMainWnd, viewID, &newContext); // When a document template creates a view, the WM_INITIALUPDATE // message is sent automatically. However, this code must // explicitly send the message, as follows. m_pNewView->SendMessage(WM_INITIALUPDATE, 0, 0); ...
CView* CMyWinApp::SwitchView(CView* pNewView) { CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView(); // Exchange view window ID's so RecalcLayout() works. #ifndef _WIN32 UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID); ::SetWindowWord(pActiveView->m_hWnd, GWW_ID, ::GetWindowWord(pNewView->m_hWnd, GWW_ID)); ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp); #else UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID); ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID)); ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp); #endif pActiveView->ShowWindow(SW_HIDE); pNewView->ShowWindow(SW_SHOW); ((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView); ((CFrameWnd*) m_pMainWnd)->RecalcLayout(); pNewView->Invalidate(); return pActiveView; }この関数は古いビュー オブジェクトのポインタを返すので、これを利用して古いビューを破棄することもできます。ただし、ビューを破棄する前にビューとドキュメント間の関連を解消するために CDocument::RemoveView を呼び出してください。
Additional query words: destructor multiple
Keywords: kbdss KBHOWTO VC10 VC15 VC20 VC40 VC41 VC42 VC4x VC50 KB99562
Technology: kbAudDeveloper kbMFC kbvc100 kbvc150 kbVC151 kbVC152 kbVC16bitSearch kbVC200 kbVC210 kbVC32bitSearch kbVC400 kbVC500 kbVC500Search kbVC600 kbVCsearch