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



Comments

  • Brug GHD Kiss lyserøde Styler kan Creat enhver frisure

    Posted by pletcherkuk on 06/15/2013 04:03pm

    [url=http://glattejernghd.webstarts.com/]Glattejern GHD[/url] GHD glattejern udføre en masse mere end producere glatte, direkte designs. Deres egen stil funktioner buede retter samt tilbud med, derfor nøjagtig samme design enhed, som du simpelthen gøre brug af for at rette en person låse kan også putte, skifte samt tilstrømning. Denne særlige fjernet reelt behov for et antal problematiske designressourcer nedenunder toilet counter-top. ghd hår australia klart, Min gruppe er virkelig noget almindeligt udseende datter i virkeligheden. Oven i det, som jeg implementerede ikke engang at være en sund dig indenfor den stil, er at se på et barn. Bestemt, indeholder de faktorer tilskyndede en selvsikkerhed. Udtrykkeligt, at kommende skabelse, Make kræve en masse mere tillid. I første omgang Banebrydende, var jeg rejser en visuelle aspekt at inkorporere forskellige tillid til at hjælpe dig mig personligt. [url=http://ghdfladjerntilbud.webs.com/]Ghd fladjern tilbud[/url] ghd fladjern anvender keramiske plader til glat, let at forme. Spændinger kontrol, kan du oprette den helt lige mellem de keramiske plader af glat hår. Produktet har også den samme anion, bevaring gør håret smidigt og blankt, for at undgå panik. Kroppen med en digital varmeindstillinger, digital display gør det nemt at vælge den ønskede funktion eller justere formen af ??temperaturen. Det kan hjælpe dig med at vælge det rigtige hår og den ønskede temperatur. Tryk på en knap, det samme har en perfekt form effekt. 1 time auto-sluk-funktionen giver dig mulighed for at bruge mere ro i sindet. Ghd glattejern så sikker og enkel betjening. Besætte stor markedsandel. Bliv en køber dille. På grund af dette, ofte forekommer falsk, så flere og flere mennesker køber ægte ghd glattejern. Vores butik, selv om salget af ghd håret sort. Men vi er regelmæssige ghd glattejern produkter. Fandt du ikke bringe alle former for falske brand skader. Vores produkt kort med det fysiske kort, er nøjagtig det samme. For at sikre sande og pålidelige produkter. Og vi sælger billige ghd glattejern, 7 * 24 online-funktioner, kan du købe på ethvert tidspunkt. Så længe du har valgt den ønskede type, udfylde personlige oplysninger, osv. relaterede emner, kan produktet blive leveret direkte til din ventende hænder. Venligst købe ghd glattejern produkter følelser før, se på vores privacy policy, Om os, transport, FAQ og mere relevante politikker, vil dette hjælpe dig til at købe vores produkter. Tak for dit samarbejde. [url=http://ghdglattejerntilbud.webs.com/]ghd glattejern tilbud[/url] Populære ghd glattejern er det bedste hårpleje eksperter, hvilket gør det et godt udvalg af stilarter du vil. Kan altid ændre din frisure. Lad alle dine udseende er blevet mere fremragende.Mange stjerner kan også godt lide styling værktøjer. Fordi det er let at bære. Kan være godt udnyttet. Enkel betjening, det forvandlet. Professionel ghd glattejern har også brug for professionelle folk til at sælge det. I forstår ikke, hvordan man bruger den samme tid, kan du bede dem om spørgsmål, kan du kende på et andet tidspunkt og sted du ønsker viden. Vi sælger ghd glattejern er det bedste, fordi vi har været igennem mange års drift og praksis. Folk skal forstå, hvad stil ghd glattejern. Til personlig pleje. Derfor mener vi, på vi vil være den bedste partner.

    Reply
  • 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.

Top White Papers and Webcasts

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds