PRB: Print Preview Displays in MDI Child Frame

Last reviewed: June 16, 1997
Article ID: Q166135
The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, versions 4.2b, 5.0

SYMPTOMS

When you display print preview for an MDI application, the preview view is displayed in the MDI child window rather than the MDI frame window.

CAUSE

The MFC sources were changed to fix a bug when mixing Active X documents and print preview.

RESOLUTION

Rebuild the MFC libraries and statically link to it.

STATUS

This behavior is by design.

MORE INFORMATION

When MFC's print preview is invoked, it searches for the frame window of the current view using GetParentFrame to display the preview view. This is done in CView::DoPrintPreview. The code below reflects some of the changes that DoPrintPreview went through between Visual C++ 4.2 and 5.0.

   // VC 4.2
   BOOL CView::DoPrintPreview(UINT nIDResource, CView* pPrintView,
      CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState)
   {
      ...
      CFrameWnd* pParent = (CFrameWnd*)AfxGetThread()->m_pMainWnd;
      ASSERT_VALID(pParent);
      ASSERT_KINDOF(CFrameWnd, pParent);
      ...
   }

   // VC 5.0
   BOOL CView::DoPrintPreview(UINT nIDResource, CView* pPrintView,
      CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState)
   {
      ...
      CFrameWnd* pParent;
      CWnd* pNaturalParent = pPrintView->GetParentFrame();
      pParent = DYNAMIC_DOWNCAST(CFrameWnd, pNaturalParent);
      if (pParent == NULL || pParent->IsIconic())
         pParent = (CFrameWnd*)AfxGetThread()->m_pMainWnd;
      ...
   }

In Visual C++ 4.2b, the preview view may not always appear in the MDI child frame. If the view is not an immediate child of the MDI child frame (for example, splitter windows), then the preview appears in the MFC frame window. This is because Visual C++ 4.2b called GetParent instead of GetParentFrame. The problem was corrected in VC 5.0.

To get back the old behavior you have to modify the MFC sources and rebuild the MFC libraries. It is not possible to override DoPrintPreview in your CView derived class since it requires the use of protected members of friend classes.

Rebuilding the MFC libraries is not supported.

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Adam Kim, Microsoft Corporation


Keywords : kbprg kbui MfcDocView MfcPrinting MfcUI kbfasttip
Technology : kbmfc
Version : 4.2b 5.0
Platform : NT WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.