Improved Print Preview Toolbar | CodeGuru

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: Compare this with the replacement […]

Written By
CodeGuru Staff
CodeGuru Staff
Apr 6, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

.  

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.