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

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds