I am using Objective Edit and Objective Grid as worksheets in the same CGXTabWnd but I have a problem with Accelerators eaten up by Objective Edit. How can I work around this?

Here is the solution for this problem.

The basic idea is to have two different accelerator tables - one for grid views and other views and one for the edit control.

When both Objective Edit and Objective Grid are used in the same CGXTabWnd you can switch the accelerator tables in the MDI child window that holds the tab window.

Here are the steps:

a) Create a separate Accelerator table and a Menu with the same resource id in Resource Studio.

b) In InitInstance create a DocTemplate:

    m_pEditTemplate = new CMultiDocTemplate(
       IDR_EDITVIEW,
       RUNTIME_CLASS(CGridSampleDoc),
       RUNTIME_CLASS(CScrltabsMDIChildWnd),        
       RUNTIME_CLASS(CObjectiveEditView));

(Don't call AddDocTemplate - this is not necessary)

In ExitInstance delete the template with

   delete m_pEditTemplate;

c) In the MDI ChildWnd register the tabwindow as follows:

BOOL CScrltabsMDIChildWnd::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
{
   CGridSampleApp* pApp = (CGridSampleApp*) AfxGetApp();
   // specify the runtime class for the first sheet
   // don't forget to register the document template in InitInstance!
   pContext->m_pNewViewClass = RUNTIME_CLASS(CGridSample9View);
   // creates the tab window
   VERIFY(m_wndTab.Create(this, _T("What's New?"), pContext));
   // each view should associated with the same document.
   // next sheets
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample10View), _T("Float Cells"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample11View), _T("Sorting"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample12View), _T("Merge Cells"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample8View), _T("1.2 Features"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSampleView), _T("Simple"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample2View), _T("Formats"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample3View), _T("Base Styles"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample4View), _T("Welcome"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample5View), _T("More Controls"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample6View), _T("Grid Children"), pContext);
   m_wndTab.CreateView(RUNTIME_CLASS(CGridSample7View), _T("Headers"), pContext);
    pContext->m_pNewDocTemplate = pApp->m_pEditTemplate;
   
   m_wndTab.CreateView(RUNTIME_CLASS(CObjectiveEditView), _T("Edit"), pContext);
   return TRUE;
}

d) Finally, the most important step is the accelerator table swapping in OnUpdateFrameMenu:

void CScrltabsMDIChildWnd::OnUpdateFrameMenu(BOOL bActivate, CWnd* pActivateWnd, HMENU hMenuAlt)
{
    CGridSampleApp* pApp = (CGridSampleApp*) AfxGetApp();
 
    CMDIChildWnd::OnUpdateFrameMenu(bActivate, pActivateWnd, 
       m_wndTab.GetBeam().GetTab(m_wndTab.GetBeam().GetCurSel()).hMenu);
   if (m_wndTab.GetActivePane()->IsKindOf(RUNTIME_CLASS(CObjectiveEditView)))
      m_hAccelTable = pApp->m_pEditTemplate->m_hAccelTable;
   else
      m_hAccelTable = pApp->m_pSplitterTemplate->m_hAccelTable;
}