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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds