Improved Print Preview Toolbar

Published on: December 2, 2000
Last Updated: February 18, 2023
EarthWeb is reader-supported. When you buy through links on our site, we may earn an affiliate commission.

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 toolbar described in this article:

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.

Rate this post

Stay on top of the latest technology trends — delivered directly to your inbox, free!

Subscription Form Posts

Don't worry, we don't spam

Written by Bobby

Lifestyle / Tech / Business. Love it!
Latest Stories

Secure your digital life with NordVPN