R.Krishnan
2006-05-25 18:34:59 UTC
I have a MDI app with multiple views. I want to have exactly one view of a
particular type. If a user clicks on the view menu (attached to mainfrm),
she will be taken to the existing view if it exists, else a new view of that
type will be created. Here is part of the code that tries to do this.
Unfortunately nothing happens (the window does not get updated at all). Am
I making a mistake getting the frame window of the view that I wish to see
(if it exists). Is there a better way of doing what I am trying to do? TIA
void CMainFrame::OnUserinput()
{
//get the active child
CMDIChildWnd * pActiveChild = MDIGetActive();
//get the current view (the one we want replaced)
CView * pCurrView = pActiveChild->GetActiveView();
CDOptimizerApp * pApp = (CDOptimizerApp*)AfxGetApp();
CDocument * pDocument = pActiveChild->GetActiveDocument();
POSITION posView = pDocument->GetFirstViewPosition();
while (posView != NULL )
{
CView *pView = pDocument->GetNextView( posView );
if (pView->IsKindOf(RUNTIME_CLASS(CUserInputView))) //this is the
replacement view, and we check if it already exists
{
//get the parent frame
CFrameWnd * pFrame = pView->GetParentFrame(); //is this line the
problem?
//set the new view as the active view
pFrame->SetActiveView(pView);
//hide the old view
pCurrView->ShowWindow(SW_HIDE);
//show the new view
pView->ShowWindow(SW_SHOW);
return;
}
}
//otherwisse create a new view
if (pActiveChild != 0)
{
CDocument * pDocument = pActiveChild->GetActiveDocument();
if (pDocument != 0)
{
CDOptimizerApp * pApp = (CDOptimizerApp*)AfxGetApp();
CDocTemplate * pTemp;
CFrameWnd * pFrame;
pTemp = pApp->GetUserInputTemplate();
pFrame = pTemp->CreateNewFrame(pDocument,pActiveChild);
if (pFrame != 0 )
{
pTemp->InitialUpdateFrame(pFrame,pDocument);
}
}
}
}
particular type. If a user clicks on the view menu (attached to mainfrm),
she will be taken to the existing view if it exists, else a new view of that
type will be created. Here is part of the code that tries to do this.
Unfortunately nothing happens (the window does not get updated at all). Am
I making a mistake getting the frame window of the view that I wish to see
(if it exists). Is there a better way of doing what I am trying to do? TIA
void CMainFrame::OnUserinput()
{
//get the active child
CMDIChildWnd * pActiveChild = MDIGetActive();
//get the current view (the one we want replaced)
CView * pCurrView = pActiveChild->GetActiveView();
CDOptimizerApp * pApp = (CDOptimizerApp*)AfxGetApp();
CDocument * pDocument = pActiveChild->GetActiveDocument();
POSITION posView = pDocument->GetFirstViewPosition();
while (posView != NULL )
{
CView *pView = pDocument->GetNextView( posView );
if (pView->IsKindOf(RUNTIME_CLASS(CUserInputView))) //this is the
replacement view, and we check if it already exists
{
//get the parent frame
CFrameWnd * pFrame = pView->GetParentFrame(); //is this line the
problem?
//set the new view as the active view
pFrame->SetActiveView(pView);
//hide the old view
pCurrView->ShowWindow(SW_HIDE);
//show the new view
pView->ShowWindow(SW_SHOW);
return;
}
}
//otherwisse create a new view
if (pActiveChild != 0)
{
CDocument * pDocument = pActiveChild->GetActiveDocument();
if (pDocument != 0)
{
CDOptimizerApp * pApp = (CDOptimizerApp*)AfxGetApp();
CDocTemplate * pTemp;
CFrameWnd * pFrame;
pTemp = pApp->GetUserInputTemplate();
pFrame = pTemp->CreateNewFrame(pDocument,pActiveChild);
if (pFrame != 0 )
{
pTemp->InitialUpdateFrame(pFrame,pDocument);
}
}
}
}