BOOL CSimpleApp::InitInstance() { // Create the Window m_View.Create(); return TRUE; }
void CMainFrame::SwitchToView(eView nView) { CView* pOldActiveView = GetActiveView(); CView* pNewActiveView = (CView*) GetDlgItem(nView); if (pNewActiveView == NULL) { switch (nView) { case STRING: pNewActiveView = (CView*) new CStringView; break; case HEX: pNewActiveView = (CView*) new CHexView; break; } CCreateContext context; context.m_pCurrentDoc = pOldActiveView->GetDocument(); pNewActiveView->Create(NULL, NULL, WS_BORDER, CFrameWnd::rectDefault, this, nView, &context); pNewActiveView->OnInitialUpdate(); } SetActiveView(pNewActiveView); pNewActiveView->ShowWindow(SW_SHOW); pOldActiveView->ShowWindow(SW_HIDE); pOldActiveView->SetDlgCtrlID( pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CStringView) ? STRING : HEX); pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST); RecalcLayout(); }
void CMainFrame::SwitchView(ViewType nType) { CView* pOldView = GetActiveView(); CView* pNewView = (CView*)GetDlgItem(nType); if(pNewView == NULL) { switch(nType) { case FORMVIEW: pNewView = (CView*)new CMultiLookView; break; case FONTVIEW: pNewView = (CView*)new CFontView; break; case PAINTVIEW: pNewView = (CView*)new CPaintView; break; } CCreateContext context; context.m_pCurrentDoc = pOldView->GetDocument(); pNewView->Create(NULL, NULL, WS_BORDER, CFrameWnd::rectDefault, this, nType, &context); pNewView->OnInitialUpdate(); } SetActiveView(pNewView); pNewView->ShowWindow(SW_SHOW); pOldView->ShowWindow(SW_HIDE); if(pOldView->GetRuntimeClass() == RUNTIME_CLASS(CMultiLookView)) pOldView->SetDlgCtrlID(FORMVIEW); if(pOldView->GetRuntimeClass() == RUNTIME_CLASS(CFontView)) pOldView->SetDlgCtrlID(FONTVIEW); if(pOldView->GetRuntimeClass() == RUNTIME_CLASS(CPaintView)) pOldView->SetDlgCtrlID(PAINTVIEW); pNewView->SetDlgCtrlID(AFX_IDW_PANE_FIRST); RecalcLayout(); }
//----------------------------------------------------------------------------- // Purpose: Replaces the current active view with a given view type. // Input : *pViewClass - // Output : CView //----------------------------------------------------------------------------- CView *CChildFrame::ReplaceView(CRuntimeClass *pViewClass) { // // Verify that there is an active view to replace. // CView *pCurrentView = GetActiveView(); if (!pCurrentView) { return(NULL); } // // If we're already displaying this kind of view, no need to go // further. // if ((pCurrentView->IsKindOf(pViewClass)) == TRUE) { return(pCurrentView); } // // Get pointer to CDocument object so that it can be used in the // creation process of the new view. Set flag so that the document // will not be deleted when view is destroyed. // CMapDoc *pDoc = (CMapDoc *)pCurrentView->GetDocument(); BOOL bAutoDelete = pDoc->m_bAutoDelete; pDoc->m_bAutoDelete=FALSE; int iRow = 0, iCol = 0; CRect rect; // Delete existing view if (bUsingSplitter) { pCurrentView->GetClientRect(rect); m_wndSplitter->GetActivePane(&iRow, &iCol); m_wndSplitter->DeleteView(iRow, iCol); } else { pCurrentView->DestroyWindow(); } // Restore the autodelete flag. pDoc->m_bAutoDelete = bAutoDelete; // Create new view and redraw. CCreateContext context; context.m_pNewViewClass = pViewClass; context.m_pCurrentDoc = pDoc; context.m_pNewDocTemplate = NULL; context.m_pLastView = NULL; context.m_pCurrentFrame=this; CView *pNewView = NULL; if (bUsingSplitter) { if (m_wndSplitter->CreateView(iRow, iCol, pViewClass, rect.Size(), &context)) { pNewView = (CView *)m_wndSplitter->GetPane(iRow, iCol); } } else { pNewView = (CView *)pViewClass->CreateObject(); if (pNewView) { CRect r; GetClientRect(r); if (!pNewView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, r, this, AFX_IDW_PANE_FIRST, &context)) { pNewView = NULL; } } } if (!pNewView) { TRACE0("Warning: couldn't create view for frame\n"); return(NULL); } pNewView->SendMessage(WM_INITIALUPDATE, 0, 0); if (bUsingSplitter) { m_wndSplitter->RecalcLayout(); } return(pNewView); }
BOOL CProdbApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CProdbDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CProdbView)); AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; POSITION pos= pDocTemplate->GetFirstDocPosition(); CDocument * pDoc = pDocTemplate->GetNextDoc(pos); CView *pView; pView = (CView*)new CProdbView; pView->Create(NULL,NULL,0L,CRect(0,0,0,0),AfxGetMainWnd(),AFX_IDW_PANE_FIRST+1,NULL); pDoc->AddView(pView); pView->OnInitialUpdate(); pView = (CView*) new CSellView; pView->Create(NULL,NULL,0L,CRect(0,0,0,0),AfxGetMainWnd(),AFX_IDW_PANE_FIRST+2,NULL); pDoc->AddView(pView); pView->OnInitialUpdate(); pView = (CView*) new CWhView; pView->Create(NULL,NULL,0L,CRect(0,0,0,0),AfxGetMainWnd(),AFX_IDW_PANE_FIRST+3,NULL); pDoc->AddView(pView); pView->OnInitialUpdate(); // The one and only window has been initialized, so show and update it. m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); return TRUE; }
///////////////////////////////////////////////////////////////////////////// // switch to the new selected view tab ///////////////////////////////////////////////////////////////////////////// BOOL CBonfireDoc::SwitchToView(CString strTab) { if (strTab == "") return FALSE; CChildFrame* pChild = (CChildFrame*)g_pMainFrame->MDIGetActive(); if (!pChild || pChild->GetActiveDocument() != this) { POSITION pos = GetFirstViewPosition(); pChild = (CChildFrame*)GetNextView(pos)->GetParentFrame(); } if (!pChild) return FALSE; CView* pViewAdd = NULL; CBonfireView* pGlobalView = NULL; CBonfireView* pBNewView = NULL; // get the view to "hide" CView* pViewDel = pChild->GetActiveView(); // if we're already displaying this kind of view, no need to go further. for (int i = 0; i < theApp.m_arAllViews.GetSize(); i++) { if ( ((CBonfireView*)theApp.m_arAllViews[i])->m_strCaption.Compare(strTab) == 0 ) { pGlobalView = (CBonfireView*)theApp.m_arAllViews[i]; break; } } if ( pViewDel && pViewDel->IsKindOf(pGlobalView->m_pClass) ) return TRUE; // check if a view of this type already exists if ( !m_pViews->Lookup(pGlobalView->m_strCaption, (void*&)pBNewView) ) { // doesn't exist so create a new view pViewAdd = (CView*)pGlobalView->m_pClass->CreateObject(); if (pViewAdd == NULL) { TRACE1("Warning: Dynamic create of view type %Fs failed\n", pGlobalView->m_pClass->m_lpszClassName); return FALSE; } // draw new view CCreateContext context; context.m_pNewViewClass = pGlobalView->m_pClass; context.m_pCurrentDoc = NULL; context.m_pNewDocTemplate = this->GetDocTemplate(); context.m_pLastView = NULL; context.m_pCurrentFrame = pChild; // draw new view if (!pViewAdd->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), pChild, AFX_IDW_PANE_FIRST, &context)) { TRACE0("Warning: couldn't create view for frame\n"); delete pViewAdd; return FALSE; } // add the view to the map pBNewView = new CBonfireView(pGlobalView); pBNewView->m_pView = pViewAdd; pBNewView->m_pClass = pViewAdd->GetRuntimeClass(); // add this view to the document's map AddViewToMap(pBNewView); // WM_INITIALUPDATE is defined in afxpriv.h pViewAdd->SendMessage(WM_INITIALUPDATE,0,0); // connect the view to the document AddView(pViewAdd); } else { pViewAdd = pBNewView->m_pView; } // save file on switching views if (theApp.m_opOptions.general.dwSaveOnSwitch && !m_xTextBuffer.GetReadOnly() && pViewDel) DoFileSave(); CSplitterWnd* pSplitter = NULL; POSITION pos = GetFirstViewPosition(); BOOL firstOne = true; while (pos) { CView* pv = GetNextView(pos); if (pv == pViewAdd) { pv->SetDlgCtrlID(AFX_IDW_PANE_FIRST); // show the view if (pBNewView->m_bAllowsSplitter) { pSplitter = (CSplitterWnd*)pViewAdd->GetParent(); // show the splitter (show the children view(s) as well) pSplitter->ShowWindow(SW_SHOW); } else // show the view pViewAdd->ShowWindow(SW_SHOW); } else { // check if the view is inside a splitter if (pv->GetParent()->GetRuntimeClass() == (CRuntimeClass*)RUNTIME_CLASS(CSplitterWnd)) { pSplitter = (CSplitterWnd*)pv->GetParent(); // hide the splitter (hide all views with the splitter) pSplitter->ShowWindow(SW_HIDE); } else { // hide the view pv->ShowWindow(SW_HIDE); pv->SetDlgCtrlID(AFX_IDW_PANE_FIRST + 255); } } TRACE("%s (%d) ", pv->GetRuntimeClass()->m_lpszClassName, (unsigned)(pv->GetDlgCtrlID() - AFX_IDW_PANE_FIRST)); if (pv == pViewDel) TRACE("= D "); if (pv == pViewAdd) TRACE("= A "); if (pv->GetRuntimeClass() == pGlobalView->m_pClass) { if (firstOne) firstOne = false; else TRACE("removing "); } } TRACE("\n"); // get rid of extra views created by the splitter if (pSplitter) { for (int cols = 1; cols < pSplitter->GetColumnCount(); cols++) pSplitter->DeleteColumn(cols); for (int rows = 1; rows < pSplitter->GetRowCount(); rows++) pSplitter->DeleteRow(rows); pSplitter->RecalcLayout(); } pViewAdd->UpdateWindow(); pChild->SetActiveView(pViewAdd); pChild->RecalcLayout(); if (pBNewView->m_bModifiedSinceRefresh) { pBNewView->m_bModifiedSinceRefresh = FALSE; if (pGlobalView->m_pClass == RUNTIME_CLASS(CXMLTreeView)) { ((CXMLTreeView*)pViewAdd)->RefreshView(); } else if (pGlobalView->m_pClass == RUNTIME_CLASS(CBrowserView)) { ((CBrowserView*)pViewAdd)->RefreshView(); } else { pBNewView->m_bModifiedSinceRefresh = TRUE; } } return TRUE; }