V
Hallo zusammen,
das Thema war vor ca. einem Jahr schonmal hier im Forum und ich habe auch einen Beispielcode. Nur ist es für mich ziemlich umständlich den ins Netz zu stellen.
Aber im Prinzip muss man in der InitInstance (oder so habe ich das halt mal gemacht) eine zweite View- Klasse mit initialisieren:
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CForm_01Doc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CForm_01View));
//RUNTIME_CLASS(CUserForm));
AddDocTemplate(pDocTemplate);
Dann habe ich im Menu natürlich einen Umschalter für die Views. Das hier sind die entsprechenden Handler in CMainFrame:
void CMainFrame::OnUpdateViewStandard(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!GetActiveView()->IsKindOf(RUNTIME_CLASS(CForm_01View)));
}
void CMainFrame::OnViewFormview()
{
// TODO: Add your command handler code here
if (m_pUserForm == NULL)
{
m_pFormView = (CForm_01View*)GetActiveView();
m_pUserForm = new CUserForm;
m_pUserForm->MyCreate(this);
}
CForm_01Doc* pDoc = (CForm_01Doc*)GetActiveDocument();
pDoc->AddView(m_pUserForm);
m_pUserForm->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_pFormView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
m_pUserForm->ShowWindow(SW_SHOW);
m_pFormView->ShowWindow(SW_HIDE);
SetActiveView(m_pUserForm);
pDoc->RemoveView(m_pFormView);
RecalcLayout(FALSE);
}
void CMainFrame::OnUpdateViewFormview(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!GetActiveView()->IsKindOf(RUNTIME_CLASS(CUserForm)));
}
void CMainFrame::OnViewStandard()
{
// TODO: Add your command handler code here
if (m_pFormView == NULL)
{
m_pUserForm = (CUserForm*)GetActiveView();
m_pFormView = new CForm_01View();
m_pFormView->Create(NULL,
NULL,
AFX_WS_DEFAULT_VIEW,
rectDefault,
this,
AFX_IDW_PANE_FIRST+1, NULL);
}
CForm_01Doc* pDoc = (CForm_01Doc*)GetActiveDocument();
pDoc->AddView(m_pFormView);
m_pFormView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_pUserForm->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
m_pFormView->ShowWindow(SW_SHOW);
m_pUserForm->ShowWindow(SW_HIDE);
SetActiveView(m_pFormView);
pDoc->RemoveView(m_pUserForm);
RecalcLayout(FALSE);
}
Das sind im Prinzip die einzigen Codestellen, die sich vom normalen SDI- Gerüst unterscheiden.
Bei mir ist es einmal ein Formview und einmal eine normale View die beide auf demselben Dokument basieren.
Ich habe das auch mal irgendwo quasi als "Kochrezept" aufgegabelt.
Grüße, Volle.
edit:
Der obere Teil mit der InitInstance ist Blödsinn (ist ja auch auskommentiert)!
[ Dieser Beitrag wurde am 12.09.2002 um 20:37 Uhr von Volle editiert. ]