Click here to Skip to main content
Click here to Skip to main content

An Advanced Preview within Doc/Vew architecture

By , 12 Oct 2000
 
  • Download source files - 25 Kb
  • Download demo application - 14 Kb
  • Sample Image - AdvancedPrev.jpg

    It is often important to MFC programmers to speed up the Print Preview display within their Document/View application.

    I would like to present some of my improvements as to the Preview procedure of printing that I experienced during my recent developpment of a large system. I extended the MFC Preview procedure to create a flicker free system using the BitBlt function.

    You can see an outline of the ExtPreviewView class definition below. This class is derived from MFCs CPreviewView described in MFC Technical Note 30. The three protected members save virtual viewport data. Through the initialization of the MFC Preview procedure, the InitVxPrintOffset() function is exectued once and sets the values of the members mentioned above. Therefore you are able to create a Bitmap on memory DC which is compatible with the Preview DC in MFC for high-speed drawing, using the maximum size of the virtual paper.

    // override MFC class
    class ExtPreviewView : public CPreviewView
    {
    	...
    protected:
    	// Original viewport point of memory DC
    	CSize m_VxPrintOffset;
    	CSize m_sizeVxVpExt, m_sizeVxWinExt;
    public:
    	void InitVxPrintOffset(CDC* pDC);
    	...
    	friend class CAdvancedPreviewView;
    };
    

    Second I add some more zoom-in lebels to the MFC as following.

    #define ZOOM_IN_150     3
    #define ZOOM_IN_200     4
    #define ZOOM_IN_400     5
    

    I add some codes to such as SetScaleSize() function and others.

    Note

    You need to set a special path for "gafximpl.h" in your work space. The path must be set same as source path of MFC class library

    This is how you do this:

    • On the Project menu, click Settings.
    • In the Settings dialog box, select the C/C++ tab.
    • Select Preprocessor from the Category drop-down list.
    • The project-specific include paths are located in the Additional include directories edit box.

    Thank you.
    Yasuhiko Yoshimura
    September/05/2000

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Yasuhiko Yoshimura
    Web Developer
    Japan Japan
    Member
    I have been programming for over 20 years and now run my own development company, Informax Inc., Osaka in Japan.
    Informax provides contract programming and engineering services. We can serve you with experiences in C++, DirectShow Filters, Shell Extension, MFC, ATL, WTL, STL, Boost, OTL, Windows2000 and XP, SymbianOS C++.
    Our speciality is the OOP and Design-Patterns solution throughout all entire project.

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    GeneralTo activate Scroll Barmembervikas amin16 Sep '05 - 0:00 
    I have a MDI application where i need to display
    text data . I need to activate the scroll bar
    but its not geting activated can anyone please
    show me the proper way for activating the scrollbar
    in MDI application .I display the data in the MainFrame
    window.
    vikas.amin@embin.com
     
    Vikas Amin
    Embin Technology
    Bombay
    vikas.amin@embin.com
    GeneralRe: To activate Scroll Barmembervikas amin30 Sep '05 - 3:11 
    For using the ScrollBars
    u need to dispaly them &
    activate them .
    If u r trying to display so
    data that is long enough not
    to fit in a view , so u want
    scrolling.
    I have tired one option that
    is using the CScrollView as
    the base class .
    else u need to do coding for
    all the scrolling fundas.
     

     
    Vikas Amin
    Embin Technology
    Bombay
    vikas.amin@embin.com
    GeneralVery Good But there was a problemememberhadjadj walid29 Aug '03 - 10:29 
    hello i want to tell you that it is exactly what i need but there is a probleme when i close the preview window , it produs a assertion faild
    and dosn't get the last view
     
    Note i am running Windows XP
     
    thant for respondingConfused | :confused:
    GeneralRe: Very Good But there was a problemememberYasuhiko Yoshimura29 Aug '03 - 15:35 
    Hi hadjadj,
     
    You might insert these improvements to 2 source files of your project and could resolve the assertion.
     
    (1)A function declaration should be inserted to "public:" section of "class CAdvancedPreviewView" definition in AdvancedPreviewView.h as follows:
     
    virtual void OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView);
     
    (2)Lines of its implimentation should be inserted in AdvancedPreviewView.cpp as follows:
     
    extern CAdvancedPreviewApp theApp;
     
    void CAdvancedPreviewView::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView)
    {
      ASSERT_VALID(pDC);
      ASSERT_VALID(pView);
       
      if (((ExtPreviewView*)pView)->m_pPrintView != NULL)
        ((CAdvancedPreviewView*)((ExtPreviewView*)pView)->m_pPrintView)->OnEndPrinting(pDC, pInfo);
      CFrameWnd* pParent;
      CWnd* pNaturalParent = pView->GetParentFrame();
      pParent = DYNAMIC_DOWNCAST(CFrameWnd, pNaturalParent);
      if (pParent == NULL || pParent->IsIconic())
        // pParent = (CFrameWnd*)AfxGetThread()->m_pMainWnd;
        pParent = (CFrameWnd*)theApp.m_pMainWnd;
      ASSERT_VALID(pParent);
      ASSERT_KINDOF(CFrameWnd, pParent);

      // restore the old main window
      pParent->OnSetPreviewMode(FALSE, ((ExtPreviewView*)pView)->m_pPreviewState);

      // Force active view back to old one
      pParent->SetActiveView(((ExtPreviewView*)pView)->m_pPreviewState->pViewActiveOld);
      if (pParent != GetParentFrame())
        // re-activate view in real frame
        OnActivateView(TRUE, this, this);
      pView->DestroyWindow(); // destroy preview view
      // C++ object will be deleted in PostNcDestroy

      // restore main frame layout and idle message
      pParent->RecalcLayout();
      pParent->SendMessage(WM_SETMESSAGESTRING, (WPARAM) AFX_IDS_IDLEMESSAGE, 0L);
      pParent->UpdateWindow();
    }

     
    Thanks.Smile | :)
    Yasuhiko Yoshimura
     

    GeneralRe: Very Good But there was a problemesussAnonymous9 Nov '03 - 9:24 
    thanks a lot il works
    Question"Shared DLL" is good. But "Static Library" ?memberAnonymous29 Jul '01 - 22:25 
    Hello all :
     
    It is a good sample. I compiled and run it well.
     
    But there is a question. I can only compiled it
    by MFC of "Shared DLL". That is, in the Project->
    Settings->General->"Microsoft Foundation Classes",
    It only can be set to "Use MFC in a Shared DLL",
    but not set to "Use MFC in a Static Library".
     
    How I can compile it by "Use MFC in a Static Library"
    Thanks a lot !
     

    Don Wang
    AnswerRe:memberAnonymous5 Aug '01 - 15:47 
    Hi Don
     
    You can compile and build the project to make the following change on a cpp file.
    There are 5 lines that the function name must be modified in ExPrevvw.cpp file.
    The name is '_AfxMultMultDivDiv' and should be renamed to 'AnotherMultMultDivDiv' or something defferent.
    That is all.Smile | :)
     
    Thanks,
    Yasuhiko Yoshimura
     

    GeneralNot too good sample of programmingsussAlexander Fedorov16 Oct '00 - 10:55 
    1. Print preview should be as much as possible similar to what you get at printer, not in memory or at display.
    2. Why ability of printing should have any relation to amount of memory available on the computer? With this solution it has...
    3. It redraws really slow after each size changing or similar operation - it is not fast at all.
    4. Class names should have "C" prefix Wink | ;-)
     
    P.S. MDI interface for print preview might be interesting, but I think I already saw it somewhere else.
    GeneralRe: Not too good sample of programmingmemberSlightly Bemused3 Dec '01 - 5:50 
    Wow you're really an a**hole. Did you have to work at it or did you just come that way
    GeneralHe has one good pointmemberTim Smith3 Dec '01 - 6:23 
    Research has actually shown that if the speed of a package is important to the user (thus to the programmer's pocketbook), the flicker free systems are bad when they take too long.
     
    The tests basically showed that if it took, let's say 1 second to display a flicker free page and 1 second to display the same page non-flicker free, then the user claimed the non-flicker free was faster and less frustrating. Even though the end user actually was waiting the same amount of time, he could at least see that the application was doing something.
     
    Tim Smith
    Descartes Systems Sciences, Inc.
    GeneralHe has one good pointmemberJörgen Sigvardsson26 Jun '05 - 10:52 
    I just realized that many hours may have been wasted on my part. Sigh | :sigh:
     
    Good music: In my rosary[^]
    GeneralNot compile : "afximpl.h" not foundsussKARIM MRIBTI14 Oct '00 - 3:39 

    GeneralRe: Not compile :sussanonymous14 Oct '00 - 3:45 
    afximpl.h is located is \MFC\SR
    GeneralRe: Not compile :sussanonymous14 Oct '00 - 3:45 
    afximpl.h is located is \MFC\SR
    GeneralRe: Not compile :sussanonymous14 Oct '00 - 3:46 
    afximpl.h is located is \MFC\SR
    GeneralDownloads dont work -- Yelp!!!susskaykay14 Oct '00 - 0:21 
    Hi Chris,
     
    I cant download anything
     
    Cheers
    KayKa
    GeneralRe: Downloads dont work -- Yelp!!!sussChris Maunder14 Oct '00 - 2:59 
    All fixed - sorry guys.
     
    cheers,
    Chris Maunde
    GeneralBroken Links to downloadssussBill13 Oct '00 - 15:48 
    The links to the source and demo files are not working

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web04 | 2.6.130516.1 | Last Updated 13 Oct 2000
    Article Copyright 2000 by Yasuhiko Yoshimura
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid