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

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");
        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

More by Author

Must Read