Switching between views-urgent
i have a MDI app whereby i have 2 views.
i switch between them by means of menu buttons.
eg. to switch to the first view i use the code
POSITION pos;
pos=GetFirstDocTemplatePosition();
CDocTemplate* pTempl=NULL;
pTempl=GetNextDocTemplate(pos); pTempl->OpenDocumentFile(NULL);
from the first to the second
POSITION pos;
pos=GetFirstDocTemplatePosition();
CDocTemplate* pTempl=NULL;
pTempl=GetNextDocTemplate(pos);
pTempl=GetNextDocTemplate(pos);
pTempl->OpenDocumentFile(NULL);
at the beginning one can chose between the views.
suppose i chose A between A,B
then i wish to switch to B
everything works.
switching back to A gives a problem( does not switch)
can anyone help?
Re: Switching between views-urgent
In your CMainFrame :
void CMainFrame::CreateOrActivateFrame(CDocTemplate* pTemplate,
CRuntimeClass* pViewClass)
{
// If a check view or book view (specified by pViewClass)
// already exists, then activate the MDI child window containing
// the view. Otherwise, create a new view for the document.
CMDIChildWnd* pMDIActive = MDIGetActive();
ASSERT(pMDIActive != NULL);
CDocument* pDoc = pMDIActive->GetActiveDocument();
ASSERT(pDoc != NULL);
CView* pView;
POSITION pos = pDoc->GetFirstViewPosition();
while (pos != NULL)
{
pView = pDoc->GetNextView(pos);
if (pView->IsKindOf(pViewClass))
{
pView->GetParentFrame()->ActivateFrame();
return;
}
}
// struct RECT wRect;
CRect wRect;
wRect = new CRect(0, 0, 50, 50);
CFrameWnd * frame = new CFrameWnd();
frame->Create(NULL, TEXT("Window !"), WS_OVERLAPPEDWINDOW, wRect, NULL, NULL, 0, NULL );
CMDIChildWnd* pNewFrame = (CMDIChildWnd*)(pTemplate->CreateNewFrame(pDoc, frame));//, WS_OVERLAPPEDWINDOW, wRect, NULL, NULL, 0, NULL));
if (pNewFrame == NULL)
return; // not created
ASSERT_KINDOF(CMDIChildWnd, pNewFrame);
pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
//MDITile(MDITILE_HORIZONTAL);
}
In your CDocument class :
void CMyDoc::OnViewA()
{
CWnd* mainWin = AfxGetMainWnd( );
CMainFrame* mainFrame = STATIC_DOWNCAST(CMainFrame, mainWin);
mainFrame->CreateOrActivateFrame(theApp.ADocTemplate, RUNTIME_CLASS(CAView));
}
Sebastien MOROSI - France Nancy(54)
DESS Informatique IRS