Is it possible to have individual menus for the different worksheets?
Override the OnUpdateFrameMenu in the MDI child window class. It is not necessary to register a doc template for each view. If you don't want the new-dialog box, you should only call AddDocTemplate() one time.
Here is the code you should insert in your InitInstance and ExitInstance method:
BOOL CScrltabsApp::InitInstance()
{
...
CMultiDocTemplate* pDocTemplate;
m_pDocTemplate = new CMultiDocTemplate(
IDR_SCRLTATYPE,
RUNTIME_CLASS(CScrltabsDoc),
RUNTIME_CLASS(CScrltabsMDIChildWnd),
RUNTIME_CLASS(CScrltabsView));
AddDocTemplate(m_pDocTemplate);
m_pDocFVTemplate = new CMultiDocTemplate(
IDR_SCRLFVTYPE,
RUNTIME_CLASS(CScrltabsDoc),
RUNTIME_CLASS(CScrltabsMDIChildWnd),
RUNTIME_CLASS(CScrltabsFormView));
...
return TRUE;
}
int CScrltabsApp::ExitInstance()
{
// need to delete the template manually,
// because it has not been added with
// AddDocTemplate().
delete m_pDocFVTemplate;
return CWinApp::ExitInstance();
}
Here is how your MDI child window should look like:
CScrltabsMDIChildWnd::CScrltabsMDIChildWnd()
{
}
CScrltabsMDIChildWnd::~CScrltabsMDIChildWnd()
{
}
BOOL CScrltabsMDIChildWnd::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CScrltabsApp* pApp = (CScrltabsApp*) AfxGetApp();
// specify the runtime class for the first sheet
// don't forget to register the document template in InitInstance!
pContext->m_pNewViewClass = RUNTIME_CLASS(CScrltabsFormView);
// Assign the template to pContext->m_pNewDocTemplate if you want to
// have different menus for the sheets
pContext->m_pNewDocTemplate = pApp->m_pDocFVTemplate;
// creates the tab window
VERIFY(m_wndTab.Create(this, "View 1", pContext));
// each view should associated with the same document.
// next sheets
m_wndTab.CreateView(RUNTIME_CLASS(CScrltabsFormView), "View 2", pContext);
// Subsequent sheets have the menu specified in pApp->m_pDocTemplate.
pContext->m_pNewDocTemplate = pApp->m_pDocTemplate;
m_wndTab.CreateView(RUNTIME_CLASS(CGXEditView), "View 3", pContext);
m_wndTab.CreateView(RUNTIME_CLASS(CScrltabsView), "View 4", pContext);
m_wndTab.CreateView(RUNTIME_CLASS(CScrltabsView), "View 5", pContext);
m_wndTab.CreateView(RUNTIME_CLASS(CScrltabsView), "View 6", pContext);
m_wndTab.CreateView(RUNTIME_CLASS(CScrltabsView), "View 7", pContext);
m_wndTab.CreateView(RUNTIME_CLASS(CScrltabsView), "View 8", pContext);
m_wndTab.CreateView(RUNTIME_CLASS(CScrltabsView), "View 9", pContext);
m_wndTab.CreateView(RUNTIME_CLASS(CScrltabsView), "View 10", pContext);
return TRUE;
}
void CScrltabsMDIChildWnd::OnUpdateFrameMenu(BOOL bActivate, CWnd* pActivateWnd,
HMENU hMenuAlt)
{
CScrltabsApp* pApp = (CScrltabsApp*) AfxGetApp();
CMDIChildWnd::OnUpdateFrameMenu(bActivate, pActivateWnd,
m_wndTab.GetBeam().GetTab(m_wndTab.GetBeam().GetCurSel()).hMenu);
}