RE: current view doesn't receive msg
 
I didn't looked into your code thoroughly, though there some points to speak
about.
I cannot see where you are specifying AFX_IDW_PANE_FIRST as the id of a
newly shown view. Also, no need to create/destroy the views every time doing
a switch. You could create them once and only do hide/show during each switch;
pOldActiveView->ShowWindow( SW_HIDE );
pNewView->ShowWindow( SW_SHOW );
Also, no need to use SetWindowLong because you can use a more simple
function to specify the desired attribute; via SetDlgCtrlID.
Suppose your two views are identified by the ids VIEW1 and VIEW2. Also
suppose your default [initial] view is CMyView and the secondly introduced
one is CSecondView. Then we van do a switch like so;
void CMainFrame::DoSwitch(UINT nViewId)
{
CView* pOldView = GetActiveView();
CView* pNewView = static_cast<CView *> ( GetDlgItem(nView) );
if (nViewId == VIEW2 && pNewView == NULL)
{
    pNewView = (CView *) new CSecondView;
    CCreateContext context;
    context.m_pCurrentDoc = pOldView->GetDocument();
    pNewView->Create(NULL, NULL, WS_BORDER | WS_CHILD, CFrameWnd::rectDefault,
this, nViewId, &context);
    pNewView->OnInitialUpdate();
}
SetActiveView(pNewView);
if (pOldView->GetRuntimeClass() == RUNTIME_CLASS(CMyView))
     pOldView->SetDlgCtrlID(VIEW1);
else
     pOldView->SetDlgCtrlId(VIEW2);
pNewView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
RecalcLayout();
--
======
Arman
"mosfet" wrote:
Hi,
I wrote a SDI application where I switch bewteen views.
The problem is now it seems I don't receive windows message after having
switched from mainview to another view.For instance I cannot enter text
in edit box.
Here is the code used to switch :
LRESULT CMainFrame::OnSwitchView( WPARAM wParam, LPARAM lParam )
{
    CViewMgr* pViewMgr = CViewMgr::GetInstance();
    CViewMgr::ViewInfo viewInfo = pViewMgr->GetViewInfo( (CViewMgr::ViewID)
wParam );
    CRuntimeClass* pNewViewClass = viewInfo.pViewClassName;
    CView* pOldActiveView = STATIC_DOWNCAST( CView, GetActiveView() );
    // If we're already displaying this kind of view, no need to go further.
    if ( pOldActiveView->IsKindOf(pNewViewClass) ) {
        return 0L;
    }
    // Set the child window ID of the active view to AFX_IDW_PANE_FIRST.
    // This is necessary so that CFrameWnd::RecalcLayout will allocate
    // this "first pane" to that portion of the frame window's client
    // area not allocated to control bars.  Set the child ID of
    // the previously active view to some other ID.
    ::SetWindowLong( pOldActiveView->m_hWnd, GWL_ID, 0 );
    // create the new view
    CCreateContext context;
    context.m_pNewViewClass = pNewViewClass;
    context.m_pCurrentDoc = GetActiveDocument();
    //pCurrentDoc->m_bAutoDelete = FALSE;
    CView* pNewView = STATIC_DOWNCAST(CView, CreateView( &context ));
    if ( pNewView != NULL ) {
        // set the commandBar
        CreateCommandBar( viewInfo.nCmdBarId );
        // the new view is there, but invisible and not active...
        pNewView->ShowWindow( SW_SHOW );
        pNewView->OnInitialUpdate();
        // redim
        SetActiveView( pNewView );
        RecalcLayout();
        pOldActiveView->DestroyWindow();
    }
#ifdef _DEBUG
    else {
        ASSERT(FALSE); // big problem !!!!
    }
#endif
    return 0L;
}
Any idea ?