Use and refine following code to develop a multiview SDI application in VC++ MFC.
void CMainFrame::Set_View(UINT ViewID)
{
// If the view the user selected is already displaying, do nothing
if( ViewID == m_Current View )
return;
// Get a pointer to the current view
CView* pCurrentView = GetActiveView();
// We are about to change the view, so we need a pointer to the runtime class
CRuntimeClass* pNewView;
// We will process a form
// First, let's change the identifier of the current view to our integer
::SetWindowLong(pCurrentView->m_hWnd, GWL_ID, m_CurrentView);
// Now we will identify what form the user selected
switch(ViewID)
{
case IDD_DMFRM2_FORM:
pNewView = RUNTIME_CLASS(CdmFrm2View);
break;
case IDD_STUDENT_DETAILS:
pNewView = RUNTIME_CLASS(CStudent_Details_Page);
break;
}
// We will deal with the frame
CCreateContext crtContext;
// We have a new view now. So we initialize the context
crtContext.m_pNewViewClass = pNewView;
// No need to change the document. We keep the current document
crtContext.m_pCurrentDoc = GetActiveDocument();
CView* pNewViewer = STATIC_DOWNCAST(CView, CreateView(&crtContext));
// Now we can create a new view and get rid of the previous one
if( pNewViewer != NULL )
{
pNewViewer->ShowWindow(SW_SHOW);
pNewViewer->OnInitialUpdate();
SetActiveView(pNewViewer);
RecalcLayout();
m_CurrentView = ViewID;
pCurrentView->DestroyWindow();
}
}
Pass the ID of the view which you want to display to the function Set_View() to display it.
No comments:
Post a Comment