BOOL CALLBACK _AfxPreviewCloseProc(CFrameWnd* pFrameWnd) { ASSERT_VALID(pFrameWnd); CPreviewView* pView = (CPreviewView*) pFrameWnd->GetDlgItem(AFX_IDW_PANE_FIRST); ASSERT_KINDOF(CPreviewView, pView); pView->OnPreviewClose(); return FALSE; }
BOOL CALLBACK _PreviewCloseProc( CFrameWnd *pFrameWnd ) /*****************************************************/ { ASSERT( pFrameWnd != NULL ); CPreviewView *pView = (CPreviewView *)pFrameWnd->GetDlgItem( AFX_IDW_PANE_FIRST ); ASSERT( pView->IsKindOf( RUNTIME_CLASS( CPreviewView ) ) ); pView->OnPreviewClose(); return( FALSE ); }
BOOL CView::DoPrintPreview(UINT nIDResource, CView* pPrintView, CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState) { ASSERT_VALID_IDR(nIDResource); ASSERT_VALID(pPrintView); ASSERT(pPreviewViewClass != NULL); ASSERT(pPreviewViewClass->IsDerivedFrom(RUNTIME_CLASS(CPreviewView))); ASSERT(pState != NULL); CFrameWnd* pParent = (CFrameWnd*)AfxGetThread()->m_pMainWnd; ASSERT_VALID(pParent); ASSERT_KINDOF(CFrameWnd, pParent); CCreateContext context; context.m_pCurrentFrame = pParent; context.m_pCurrentDoc = GetDocument(); context.m_pLastView = this; // Create the preview view object CPreviewView* pView = (CPreviewView*)pPreviewViewClass->CreateObject(); if (pView == NULL) { TRACE0("Error: Failed to create preview view.\n"); return FALSE; } ASSERT_KINDOF(CPreviewView, pView); pView->m_pPreviewState = pState; // save pointer pParent->OnSetPreviewMode(TRUE, pState); // Take over Frame Window #ifdef _MAC if (nIDResource == AFX_IDD_PREVIEW_TOOLBAR) { HINSTANCE hInst = AfxFindResourceHandle( MAKEINTRESOURCE(AFX_IDD_PREVIEW_TOOLBAR), RT_DIALOG); HRSRC hResource = FindResource(hInst, MAKEINTRESOURCE(AFX_IDD_PREVIEW_TOOLBAR), RT_DIALOG); HGLOBAL hdt = NULL; if (hResource != NULL) hdt = LoadResource(hInst, hResource); DLGTEMPLATE* pdt = NULL; if (hdt != NULL) pdt = (DLGTEMPLATE*)LockResource(hdt); if (pdt != NULL) { CRect rectParent; pParent->GetClientRect(&rectParent); int cxToolbar = MulDiv(LOWORD(GetDialogBaseUnits()), pdt->cx, 4); if (cxToolbar > rectParent.Width()) nIDResource = AFX_IDD_PREVIEW_SHORTTOOLBAR; UnlockResource(hdt); FreeResource(hdt); } } #endif // Create the toolbar from the dialog resource pView->m_pToolBar = new CDialogBar; if (!pView->m_pToolBar->Create(pParent, MAKEINTRESOURCE(nIDResource), CBRS_TOP, AFX_IDW_PREVIEW_BAR)) { TRACE0("Error: Preview could not create toolbar dialog.\n"); pParent->OnSetPreviewMode(FALSE, pState); // restore Frame Window delete pView->m_pToolBar; // not autodestruct yet pView->m_pToolBar = NULL; pView->m_pPreviewState = NULL; // do not delete state structure delete pView; return FALSE; } pView->m_pToolBar->m_bAutoDelete = TRUE; // automatic cleanup // Create the preview view as a child of the App Main Window. This // is a sibling of this view if this is an SDI app. This is NOT a sibling // if this is an MDI app. if (!pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0,0,0,0), pParent, AFX_IDW_PANE_FIRST, &context)) { TRACE0("Error: couldn't create preview view for frame.\n"); pParent->OnSetPreviewMode(FALSE, pState); // restore Frame Window pView->m_pPreviewState = NULL; // do not delete state structure delete pView; return FALSE; } // Preview window shown now pState->pViewActiveOld = pParent->GetActiveView(); CView* pActiveView = pParent->GetActiveFrame()->GetActiveView(); if (pActiveView != NULL) pActiveView->OnActivateView(FALSE, pActiveView, pActiveView); if (!pView->SetPrintView(pPrintView)) { pView->OnPreviewClose(); return TRUE; // signal that OnEndPrintPreview was called } pParent->SetActiveView(pView); // set active view - even for MDI // update toolbar and redraw everything pView->m_pToolBar->SendMessage(WM_IDLEUPDATECMDUI, (WPARAM)TRUE); pParent->RecalcLayout(); // position and size everything pParent->UpdateWindow(); return TRUE; }