Here's what I've done. I added a 2nd CDocument class, a CFormView class and a CRecordset class in addtion to the Document and View classes created initially by Class Wiz. I created a dialog to be used by the CFormView. Here's what I want to do. When the user selected an option from the menu I want to 'change' to my second document/view. This is not like an MDI app where the user can go from window to windows, rahter, the first view can be hidden and not accesable.
I added the following code to my CMainFrame class:
NOTE: ViewID ranges from 1-n. The various ViewID's are defined in a header file as constans. And, yes, I included the header file in the compile or else I would have received errors.
void CMainFrame::SelectView(UINT ViewID)
{
CView* pOldActiveView = NULL;
pOldActiveView = (CView*)GetActiveView(); // get the current view
// get pointer to new view if it exists
// if it does not exist the pointer will be null
CView* pNewActiveView = NULL;
pNewActiveView = (CView*)GetDlgItem(ViewID);
// if this is the first time around for the new view
// the view will not exist - create it!
if(pNewActiveView == NULL)
{
switch(ViewID)
{
case MAIN_VIEW:
// pNewActiveView = (CView*) new CMainMenuView;
break;
//
// the AR_VIEW is the case which I am trying to active
//
case AR_VIEW:
pNewActiveView = (CView*) new CMenuARFormView;
break;
//
// this will be another document/view I will want to
// invoke once I figure this out.
//
case TP_VIEW:
// pNewActiveView = (CView*) new CTicketMenuView;
default:
AfxMessageBox("Invalid View ID"
return;
}
// Switch the views
// Obtain the current view context to apply to the new view
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, FrameWnd::rectDefault, this, ViewID, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView); // Active the new view
pOldActiveView->ShowWindow(SW_HIDE); // hide the old view
pNewActiveView->ShowWindow(SW_SHOW); // show the ew view
pOldActiveView->SetDlgCtrlID(m_CurrentViewID); // set the old view id
pNewActiveView-SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_CurrentViewID = ViewID; // save the new view id
RecalcLayout();
}
When the suers selects to approprate option the following code is executed and calls the above funciton:
void CMainMenuView::OnMenuAr()
{
((CMainFrame*)GetParentFrame())->SelectView(AR_VIEW);
}
When I execute the program and invoke the menu function to call OnMenuAr [see above], the view does not change to my dialog which is attached to the CFormView object I created. Add the menu bar at top gos 'dead'. I can click on X to kill the app. What I have not done in order to allow the invoking of this second view/document in my app.
I added the following code to my CMainFrame class:
NOTE: ViewID ranges from 1-n. The various ViewID's are defined in a header file as constans. And, yes, I included the header file in the compile or else I would have received errors.
void CMainFrame::SelectView(UINT ViewID)
{
CView* pOldActiveView = NULL;
pOldActiveView = (CView*)GetActiveView(); // get the current view
// get pointer to new view if it exists
// if it does not exist the pointer will be null
CView* pNewActiveView = NULL;
pNewActiveView = (CView*)GetDlgItem(ViewID);
// if this is the first time around for the new view
// the view will not exist - create it!
if(pNewActiveView == NULL)
{
switch(ViewID)
{
case MAIN_VIEW:
// pNewActiveView = (CView*) new CMainMenuView;
break;
//
// the AR_VIEW is the case which I am trying to active
//
case AR_VIEW:
pNewActiveView = (CView*) new CMenuARFormView;
break;
//
// this will be another document/view I will want to
// invoke once I figure this out.
//
case TP_VIEW:
// pNewActiveView = (CView*) new CTicketMenuView;
default:
AfxMessageBox("Invalid View ID"
return;
}
// Switch the views
// Obtain the current view context to apply to the new view
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, FrameWnd::rectDefault, this, ViewID, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView); // Active the new view
pOldActiveView->ShowWindow(SW_HIDE); // hide the old view
pNewActiveView->ShowWindow(SW_SHOW); // show the ew view
pOldActiveView->SetDlgCtrlID(m_CurrentViewID); // set the old view id
pNewActiveView-SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_CurrentViewID = ViewID; // save the new view id
RecalcLayout();
}
When the suers selects to approprate option the following code is executed and calls the above funciton:
void CMainMenuView::OnMenuAr()
{
((CMainFrame*)GetParentFrame())->SelectView(AR_VIEW);
}
When I execute the program and invoke the menu function to call OnMenuAr [see above], the view does not change to my dialog which is attached to the CFormView object I created. Add the menu bar at top gos 'dead'. I can click on X to kill the app. What I have not done in order to allow the invoking of this second view/document in my app.