Improved Print Preview Toolbar

.  

Print preview is an extremely useful part of the MFC Doc/View architecture. However, the appearance of the print preview toolbar leaves a lot to be desired, and has not been updated since print preview was first added to MFC. The usual MFC-supplied preview button bar is shown below:

MFC default preview

Compare this with the replacement toolbar described in this article:

Improved preview

The replacement toolbar functions in exactly the same way as the default button bar, but has a more modern appearance. The normal text-based buttons are replaced with ownerdraw ones that use bitmaps for the various actions. Tooltips are available for the bitmapped buttons to help users make their selection.

To use the improved version requires only a few simple steps:

1. Add a few bitmap, string and dialog resources for the replacement toolbar (see the demo project for details)

2. Addition of a new CMyPreviewView class to control the preview toolbar, and a CMappedBitmapButton class to handle the buttons used. (Source files CMyPreviewView.cpp and CMappedBitmapButton.cpp)

3. Addition of a message handler inside your view class to produce print preview using the enhanced toolbar:


void CYourView::OnFileImprovedprintpreview() 
{
    // need to use CMyPreviewView class
    CPrintPreviewState* pState = new CPrintPreviewState;

    if (!DoPrintPreview(IDD_PREVIEW, this, RUNTIME_CLASS(CMyPreviewView), pState))
    {
        TRACE0("Error: OnFileImprovedprintpreview failed.\n");
        AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
        delete pState; // preview failed to initialize, delete State now
    }
}

The demo project (VC6) shows what needs to be done, and includes the various resources that must be added. The demo program allows you to compare the default and improved print preview toolbars in a simple application built around a CEditView window.

Download demo project - 56 KB



Comments

  • Toolbar & Menubar with CFormView

    Posted by Legacy on 09/06/2002 12:00am

    Originally posted by: Sree

    I have a CFormView based SDI app and when i pass the "this" pointer of the view to the PrintPreview class, the preview shows the toolbar and menubar also. how to hide them ?

    Reply
  • It works!

    Posted by Legacy on 08/21/2001 12:00am

    Originally posted by: Karoly Arnhoffer

    I tried this prview class, ant it works fine. I think it's much better than the old one. My question is whether it is possible to display more than two pages on the preview, or the whole print preview depends on version of VCPP. (Cos I'd like to use the frameworks, its good for me. I find difficult to prepare an own previewing mechanism.)

    Arnhoffer Karoly
    ak123@hszk.bme.hu

    Reply
  • EXCELLENT, BUT...

    Posted by Legacy on 06/27/2001 12:00am

    Originally posted by: J. H. Paul

    It's an excellent work but can anybody know how to do printing setup in the preview?
    Thank you

    Reply
  • Toolbar doesnt appear

    Posted by Legacy on 06/17/1999 12:00am

    Originally posted by: Paul Nadin

    I am trying to implement Print Preview on a set of CListView derived classes but have found it doesnt work properly.(for me)

    I cant get the default toolbar to appear so I tried your code as a possible fix to my problem, but without success.

    The Preview pane displays OK but without the expected preview toolbar. The framework hides my menu and toolbar but leaves a gap between the preview pane and the window titlebar showing the list control headers from behind. The window behaves as though the list control was in the foreground despite being hidden by the Preview Pane.

    anyone know what I'm doing wrong ?

    --
    Regards,
    Paul

    Reply
  • Great! But...

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

    Originally posted by: yasuhiko yoshimura

    This is greate code.
    But would you please make it more tendy like the toolbar of Word97's preview?

    Thanks.

    y. yoshimura

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

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds