Print Preview in MDI Frame

Between Visual C++ 4.2 and 5.0 the behavior of displaying the print preview in MDI applications has changed. This issue is covered by MSDN Article ID: Q166135

In 5.0 the preview is not longer displayed in the MDI-Frame, it's in the MDI-Child. This results in a small preview area which is even smaller, if there are docking toolbars, and the user interface is fully functioning during preview. I think that this is unusable for many applications.

The reason is the following determination of the parent frame:


   // 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;
      ...
   }

To get back the old behavior the following this must be done:

1. Write your own DoPrintPreview() in your MDI View class

This function is mostly a copy of CView::DoPrintPreview() with 2 changes.

   BOOL CMDIView::DoPrintPreview(UINT nIDResource, CView* pPrintView,
      CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState)
   {
      ...
      // 1.) Use the MDI Frame as the parent
      CFrameWnd* pParent = (CFrameWnd*)AfxGetThread()->m_pMainWnd;
      ASSERT_VALID(pParent);
      ASSERT_KINDOF(CFrameWnd, pParent);
      ...

      ...
      // 2.) Deactivate the MDIChild and display the desired menu
      CChildFrame *pChildFrame = DYNAMIC_DOWNCAST (CChildFrame, pParent->GetActiveFrame());

      if (pChildFrame)
      {
          // Save the original shared menu
          HMENU hMenuShared = pChildFrame->GetSharedMenu ();

          // Set the displayed menu during preview to NULL or to the desired menu
          pChildFrame->SetSharedMenu (NULL);

          // Deactivate the MDIChild
          pChildFrame->SendMessage (WM_MDIACTIVATE, 0, 0);

          // Restore the shared menu
          pChildFrame->SetSharedMenu (hMenuShared);
      }
      ...
   }

2. Make a derivation of CPreviewView

In CView::DoPrintPreview(), lots of protected members from CPreviewView are used. This isn't longer possible in your own DoPrintPreview().

The solution is to declare the CMDIView as a friend of CMyPreviewView.


    class CMyPreviewView : public CPreviewView
    {
    protected:
        CMyPreviewView();
        DECLARE_DYNCREATE(CMyPreviewView)
        ...

        friend class CMDIView;
    };

3. Write menu access function in the MDI Child Frame


    class CChildFrame : public CMDIChildWnd
    {
        DECLARE_DYNCREATE(CChildFrame)
    public:
        CChildFrame();

    // Operations
    public:
        HMENU GetSharedMenu () const { return m_hMenuShared; }
        void SetSharedMenu (HMENU hMenuShared) { m_hMenuShared = hMenuShared; }
    ...
    };

Download demo project - 20 KB

IT Offers

Comments

  • Jordan shoes mentioned Gene to buy the manufacturer, a disunion of Nike

    Posted by TaddyGaffic on 04/24/2013 06:18am

    Where did that get us? A bunch of banks writing loans that they didnt care if poeple would be able to pay for because they were conforming [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache[/url] loans and Fannie and Freddie would back them. And their $150+ billion losses show that they are just as unable to predict or control the market as the rest of us. It won't work because it doesn't reward investors for taking the risks involved. In order to set a good example of following your dreams, you may wish to consider strictly limiting, or eliminating TV from your life. When people are involved in pursuing their dreams they often find that they do not have the time to watch TV. TV just gets in the way of pursuing other dreams.. Take a limousine ride with Aerosmith on one of the fastest rollercoaster you have to face. Live shows throughout the day from Beauty and the Beast [url=http://markwarren.org.uk/goodbuy.cfm]nike free uk[/url] will bring memories flooding back for young and old. You can get closer to the action and feel that he wanted to be in the spotlight. Other technology advancements are the midsole. It has a compression molded EVA for lasting impact protection. A Vibrakill shock-absorber in the heel provides a lot of [url=http://turbo-vac.co.uk/components_13.cfm]nike free[/url] comfort, and the Exact Pro technology combines a pebax plate and a Dynamic camflex in the forefoot for improved energy return on every step. Meindl Borneo Lady Pro - This shoe is just one of my wifes most popular hiking boots. It is appropriate for lengthy outdoor hikes and you can actually do a tiny stretch of hill hiking whilst sporting them. This product also includes memory foam

    Reply
  • probably user can try the [zoom in] button?

    Posted by Legacy on 02/03/1999 12:00am

    Originally posted by: levin

    probably user can try the [zoom in] button?

    Reply
  • MFC behaviour changements

    Posted by Legacy on 01/20/1999 12:00am

    Originally posted by: Michael Walz


    The main reason why I have not yet switched to VC5 and MFC 4.2 is
    the fact that he behavior of displaying the print preview in MDI
    applications has changed. In my application this new behaviour
    was inacceptable because the user interface is still fully functioning
    during preview and some on the user interface commands could result
    in strange behaviours. I'm sure that there are many more programmers
    that had to deal with this.

    It's unbelievable that the folks at M$ dare change the behaviour
    of MFC in such a way and didn't even offer an easy way to make
    print preview behave as before. New features and bug corrections are
    ok but old features should remain exactly as they are.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Go Deeper

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds