Article ID: 141333
Article Last Modified on 11/21/2006
119591 How to Obtain Microsoft Support Files from Online Services
VSWAP.EXE -d
CVswapApp::InitInstance CVswapApp::SwitchView CVswapApp::SaveActiveViewsDataThe standard InitInstance code creates an initial frame, document, and view during the call to OnFileNew. The code added to the end of the InitInstance in this sample creates the view objects for the extra views used in this application and stores their pointers in a CVswapApp member array. It then cycles through a loop which creates the windows for the view objects. Each view window is created with a unique child window ID and a CCreateContext object that associates each view with the same CDocument object, which was created by OnFileNew. Finally, the sample code triggers the OnInitialUpdate for the extra views.
The SwitchView function is included here as a reference.
CView* CVswapApp::SwitchView( UINT nIndex )
{
ASSERT( nIndex >=0 && nIndex < NUMVIEWS );
CView* pNewView = m_pViews[nIndex];
CView* pActiveView =
((CFrameWnd*) m_pMainWnd)->GetActiveView();
if ( !pActiveView ) // No currently active view
return NULL;
if ( pNewView == pActiveView ) // Already there
return pActiveView;
// Update Doc's data if needed
// Don't change view if data valiation fails
if ( ! SaveActiveViewsData() )
{
return pActiveView;
}
m_nCurView = nIndex; // Store the new current view's index
// exchange view window IDs so RecalcLayout() works
UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID);
::SetWindowWord(pActiveView->m_hWnd, GWW_ID,
::GetWindowWord(pNewView->m_hWnd, GWW_ID));
::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp);
// Display and update the new current view - hide the old one
pActiveView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView);
((CFrameWnd*) m_pMainWnd)->RecalcLayout();
pNewView->Invalidate();
return pActiveView;
}
COLLECT (SDI) ENROLL (SDI) VWRPLC (MDI) SPLIT (Splitter).For more information on DDX and DDV routines, please see Technical Note 26: DDX and DDV Routines in the Microsoft Development Library.
99562 Switching Views in a Single Document Interface Program
Additional query words: VSWAP VSWAP32
Keywords: kbdownload kbcode kbdocview kbfile kbnoupdate kbsample kbuidesign KB141333