1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
CBaseFrame::stViewInfo CBaseFrame::m_ViewInfo[] =
{
{ IDD_MAIN_FORM, CBaseFrame::CREATE_ONCE, AFX_IDW_PANE_FIRST + 0, NULL },
{ IDD_WELCOME_DLG, CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST + 1, NULL },
{ IDD_WIZZARD_DLG, CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST + 2, NULL },
{ IDD_OPTIONS_DLG, CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST + 3, NULL },
{ IDD_CNX_DLG, CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST + 4, NULL },
{ IDD_SCHEDULE_DLG, CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST + 5, NULL },
{ IDD_HISTORY_DLG, CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST + 6, NULL },
{ IDD_ABOUT_DLG, CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST + 7, NULL },
};
BOOL CBaseFrame::InitViews(UINT a_FirstViewId)
{
BOOL bRet = FALSE;
CView* pCurView = NULL;
int iCurViewIdx = -1;
if ((m_pMainApp != NULL) ){
m_pFrame = static_cast<CFrameWnd*>(m_pMainApp->m_pMainWnd);
if (m_pFrame != NULL){
pCurView = m_pFrame->GetActiveView();
if (pCurView != NULL){
iCurViewIdx = GetIndexFromId( a_FirstViewId );
if (iCurViewIdx != -1){
m_ViewInfo[ iCurViewIdx ].pView = pCurView;
bRet = TRUE;
}
}
}
}
return bRet;
}
CView* CBaseFrame::CreateView( UINT a_ViewId, int a_iIndex )
{
CView* l_pView = NULL;
CDocument* l_pCurrentDoc = m_pFrame->GetActiveDocument();
// Initialize a CCreateContext to point to the active document.
// With this context, the new view is added to the document
// when the view is created in CView::OnCreate().
CCreateContext newContext;
newContext.m_pNewViewClass = NULL;
newContext.m_pNewDocTemplate = NULL;
newContext.m_pLastView = NULL;
newContext.m_pCurrentFrame = m_pFrame;
newContext.m_pCurrentDoc = l_pCurrentDoc;
CRect rect(0, 0, 0, 0); // gets resized later
switch (a_ViewId)
{
case IDD_MAIN_FORM: { l_pView = new CMainView(); break; }
case IDD_WELCOME_DLG: { l_pView = new CWelcomeView(); break; }
case IDD_WIZZARD_DLG: { l_pView = new CBackupSimView(); break; }
case IDD_OPTIONS_DLG: { l_pView = new COptionsView(); break; }
case IDD_CNX_DLG: { l_pView = new CConnectionView(); break; }
case IDD_SCHEDULE_DLG: { l_pView = new CScheduleView(); break; }
case IDD_HISTORY_DLG: { l_pView = new CHistoryView(); break; }
case IDD_ABOUT_DLG: { l_pView = new CAboutView(); break; }
}
// views are created with the style of AFX_WS_DEFAULT_VIEW
// In MFC 4.0, this is (WS_BORDER | WS_VISIBLE | WS_CHILD)
l_pView->Create(NULL, NULL,
(AFX_WS_DEFAULT_VIEW & ~WS_VISIBLE),
rect, m_pMainApp->m_pMainWnd,
m_ViewInfo[a_iIndex].iSysViewId, &newContext);
return l_pView;
}
//************************************************************************
// CMainApp::OnSwitchView()
//
// Purpose:
// Switch from one view to another. Save and validate current view's
// data to document - fail if validation fails.
//
// Parameters:
// UINT nIndex (of view to switch to)
//***********************************************************************
LRESULT CBaseFrame::OnSwitchView( WPARAM wParam, LPARAM lParam )
{
int iCurViewIdx = 0;
int iNewViewIdx = 0;
CView* pCurView = NULL;
CView* pNewView = NULL;
BOOL bDestroyOldView = FALSE;
UINT ViewId = (UINT) wParam;
CDocument* pCurrentDoc = GetActiveDocument();
BOOL bAutoDelete = FALSE;
//Get current active view
pCurView = m_pFrame->GetActiveView();
if ( pCurView == NULL)
return 0L;
//Get Curview and NextView index
iCurViewIdx = GetIndexFromView( pCurView );
iNewViewIdx = GetIndexFromId( wParam );
if ((iCurViewIdx == -1) || (iNewViewIdx == -1))
return 0L;
TRACE( _T("CViewMgr::SwitchView : pCurView[%d] = 0x%x\r\n"), iCurViewIdx, pCurView );
pNewView = m_ViewInfo[iNewViewIdx].pView;
// View is already displayed
if ( pNewView == pCurView ){
return 0L/*pCurView*/;
}
// New view is NULL - we must create it
if ( pNewView == NULL ){
pNewView = CreateView( ViewId, iNewViewIdx);
TRACE( _T("pNewView = 0x%x\r\n"), pNewView );
if (pNewView != NULL){
// Save new created view
m_ViewInfo[iNewViewIdx].pView = pNewView;
}
}//pView == NULL
// exchange view window ID's so RecalcLayout() works
UINT temp = ::GetWindowLong(pCurView->m_hWnd, GWL_ID);
::SetWindowLong(pCurView->m_hWnd, GWL_ID,
::GetWindowLong(pNewView->m_hWnd, GWL_ID));
::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);
// Hide Old view
pCurView->ShowWindow(SW_HIDE);
//OnInitialUpdate() is not called as a result of calling CreateView() above.
//It is not always called by the framework, so it is called here:
pNewView->OnInitialUpdate();
// Now show the new view
pNewView->ShowWindow(SW_SHOW);
m_pFrame->SetActiveView(pNewView);
m_pFrame->RecalcLayout();
pNewView->Invalidate();
//Make sure that the document won't be destroyed when the view is destroyed.
//m_bAutoDelete is a public, but non-documented member of CDocument.
if ( m_ViewInfo[iCurViewIdx].eCreationMode == CREATE_AND_DESTROY){
BOOL bAutoDelete = pCurrentDoc->m_bAutoDelete;
pCurrentDoc->m_bAutoDelete = FALSE;
pCurView->DestroyWindow();
pCurrentDoc->m_bAutoDelete = bAutoDelete;
}
// try to destroy old view
//if ( m_ViewInfo[iCurViewIdx].eCreationMode == CREATE_AND_DESTROY){
// ::SendMessage(pCurView->m_hWnd, WM_DESTROY, 0, 0);
// //pCurView->DestroyWindow();
// m_ViewInfo[iCurViewIdx].pView = NULL;
//}
return 0L/*pNewView*/;
} |
Partager